ARM compiler misbehaves ?
Bill Gatliff
bgat@billgatliff.com
Thu Apr 29 01:23:00 GMT 2004
Grant:
>test_struct.test_short = 0x1234;
>printf("%04x\n", test_struct.test_short);
>
>_may_ work. I don't think it's guaranteed to work, though.
>
Actually, I'm pretty sure it is guaranteed to work as long as the
compiler can see the "packed" attribute during compilation (if it
couldn't, that would be a serious structural problem in your source code!).
>> test_pointer = &test_var.test_short;
>>
>>
>
>test_pointer now points to an odd address. Dereferencing it
>will almost certainly not work right, since the compiler
>doesn't generate run-time checks for misaligned pointers.
>
>
>
>> *test_pointer = 0x789A;
>>
>>
>
>Doing a 16-bit access to an odd address is undefined on ARM.
>
Yep. The above is 'bad day' code waiting to happen. Legal in "straight
C", gets potentially broken when a non-portable, non-standard operation
like the packed attribute is used.
If you aren't sure we're right, take out the "packed" attribute and try
again. It should work fine then. Also, stop the debugger after the
assignment to test_pointer and examine its value: it should be 16-bit
aligned.
b.g.
--
Bill Gatliff
Professional embedded GNU training.
bgat@billgatliff.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
More information about the crossgcc
mailing list