writing value to pointer

From: Frank Benoit (nospam_at_xyz.com)
Date: 07/17/03


Date: Thu, 17 Jul 2003 15:30:33 +0200

On ARM with GCC 2.95.3:

typedef unsigned char uint8;
typedef unsigned short uint16;

uint8 buffer[100];

uint16 * ptr0 = ( uint16 * ) & buffer[0];
uint16 * ptr1 = ( uint16 * ) & buffer[1];
uint16 * ptr2 = ( uint16 * ) & buffer[2];

*ptr0 = 0x1234; // OK, writes into buffer[0-1]
*ptr1 = 0x1234; // Error, writes into buffer[0-1]
*ptr2 = 0x1234; // OK, writes into buffer[2-3]

//------------------------------------
How can I force the compiler to generate code, that works correct?

Frank
benoit at tionex de



Relevant Pages

  • Re: Filtering endless #defines
    ... To be frank, ... because of the rampant use of #define's. ... If that was my only issue, I'd be home free. ... Does your compiler have an option to store the output from the ...
    (comp.lang.c)
  • Re: Zero length Objects
    ... Frank J. Lhota wrote: ... > had an interesting and informative discussion of how a compiler should ... Fighting for peace is like fucking for virginity! ...
    (comp.lang.ada)
  • Re: sizeof(Uint8)
    ... typedef struct myStruct { ... Uint16 somemetadata; ... dein Uint16 auf einer durch 2 teilbaren Adresse liegen muss. ... die ist je nach Compiler und Prozessor anders layoutet. ...
    (de.comp.lang.c)
  • Re: Obfuscation - sinnfrei?
    ... Frank Dzaebel schrieb: ... Für alle Code-Arten (auch Assembler) gibt es mittlerweile Disassembler/Reflectoren. ... also aus Maschienencode wieder eine Hochsprache zusammenzubauen ist ja nicht ganz so einfach bzw. eigentlich fast unmöglich. ... Der Watcom Compiler drehte z.B. am Stack rum, ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Filtering endless #defines
    ... To be frank, ... because of the rampant use of #define's. ... puts the inactive code in all gray color, ... compiler ...
    (comp.lang.c)