Mail Archives: djgpp/1993/10/05/12:34:10
> Is it possible to pack a struct, so that it uses the least amount of memory
> required for the data.
> example:
> struct {
> uchar reg;
> uchar *scr;
> uchar r,g,b;
> } RGB;
> Normally sizeof(RGB)==12. Is it possible to tell the compiler NOT to pad out
> structs to multiple-of-4 sizes. I understand that in the above example,
> swapping reg and scr would result in a sizeof()==8 (which is what I want),
> but when you are working with file headers that are not of your own design,
> you can not simply reorder your struct.
As of gcc 2.4.1 you can use the "__attribute__((packed))" construct to
cause an object to pack (byte boundaries). Consult the gcc
documentation for specifics on using this.
DJ
- Raw text -