On 2008-02-13, Chris Liechti <[email protected]> wrote:
> WenZhan Song schrieb:
>> Our group are using tinyos with msp430 and find the msp430-gcc compiler
>> can not handle packed struct correctly. See the below code scratch and
>> test results. I wonder whether this will be fixed in near future.
>>
>> typedef struct tTestPointer
>> {
>> uint8_t m;
>> uint16_t k;
>> uint32_t l;
>> } __attribute__ ((packed)) tTestPointer;
>
> it is the hardware that can not handle word reads from odd
> addresses.
True. That's the same for many other targets.
> and for constructs like the above is gcc generating code that
> reads words.
That's the problem. On all of the other targets for which I've
used gcc, it generates byte accesses.
> for the same reason its a bad idea to typecast a byte array to
> a struct or int array.
It obviously can't work if you "go behind the compiler's back"
by casting pointers carelessly, but in the above case gcc knows
the fields are in a packed array and for other targets
generates correct code.
> what would you expect in this case? terribly inefficient byte
> reads for the larger integer types?
Yes. That's the only solution and that's what gcc does on
other targets.
--
Grant Edwards grante Yow! I invented skydiving
at in 1989!
visi.com