This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ARM compiler misbehaves ?


On Thu, Apr 29, 2004 at 04:35:26PM +0100, Richard Earnshaw wrote:

>> So casting the pointer to a (char*) or (void*) should guarantee
>> that the memcpy() works correctly.  Assuming that the "&"
>> operator on a packed field correctly returns the address of the
>> first byte in the field.
> 
> No.  The compiler is entitled to infer alignment (and other
> things, such as aliasing, but lets not go there right now)
> through casts.
> 
> If you lie to the compiler it's entitled to do all sorts of
> random things.  Putting something that isn't suitably aligned
> into a pointer that implies some alignment is lying to the
> compiler...  It doesn't matter how much you try to camouflage
> it, once you've lied you get exactly what you deserve.

Boy.  The C standards people have sure worked hard to make it
as difficult as possible to deal with externally constrained
data layouts (e.g. network protocol frames).

The only thing guaranteed to work is to declare everything as
an array of unsigned chars and bash bytes around manually.

-- 
Grant Edwards
grante@visi.com

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]