Mail Archives: djgpp/1998/04/22/21:45:46
>I've read the faq again and I've found the solution:
>
> char x[n] __attribute__ ((packed));
That will indeed force your structures to be packed, but before you just
jump into doing this, ask yourself whether it is really needed. The
compiler adds this padding for a good reason: it makes things much
faster. I think that in 99% of cases, it is better to change your code
than to force a structure to be packed. The usual reason for needing
this is when you are doing block reads from some disk file format, but
it is IMHO much better to implement such things as a series of calls to
read individual bytes, words, and dwords. At minimum performance
overhead, that insulates you from any changes in structure padding, data
type sizes, and endianess, and in the long run it will make your code
much more portable and robust.
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Pigs use it for a tambourine" - Frank Zappa
- Raw text -