Quote:>Hi,
>Does anyone know the command line option for Packing Structures under
>gcc? For example, the following structure normally takes up 8 bytes
>of storage because gcc by default try to allign each element of the
>structure on a double word boundary:
>struct { // should only take up 5 bytes
> char x; // 1 byte
> int y; // 4 bytes
>}
>How do I turn this feature off?
>Thanks for your help on this.
>Khanh Doan
Try the following:
#ifdef __GCC__
# define PACKED __attribute__((packed))
#else
# define PACKED
#endif
struct structname { // should only take up 5 bytes
char x PACKED; // 1 byte
int y PACKED; // 4 bytes
Quote:};
Now, if you want an array of this struct of which the individual members
are _also_ not aligned you'd also say:
struct structname a_struct[10] PACKED; // Takes up 50 bytes.
Oh, I got this magic from a few hints in /usr/include/linux/sysv_fs.h :)
Hope this helps, Mike.
--
+ Miquel van Smoorenburg + Cistron Internet Services + Living is a |