On 2008-02-14, Grant Edwards <[email protected]> wrote:
>> 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.
The painful part of that approach is that it's used for all
fields in a packed struct, even if the compiler could (in
theory) figure out which fields are properly aligned and which
ones aren't:
struct packeds
{
char c;
unsigned u;
char c2[3];
unsigned u2;
} __attribute__((packed));
struct packeds ps;
unsigned p1(void)
{
return ps.u;
}
unsigned p2(void)
{
return ps.u2;
}
If you look at the code generated for the ARM, both u and u2
fields are accessed byte-by-byte even though u2 is
word-aligned. That's the price you pay for using a packed
struct.
--
Grant Edwards grante Yow! YOU PICKED KARL
at MALDEN'S NOSE!!
visi.com