packed, aligned

Richard Henderson rth@redhat.com
Sun Feb 11 11:15:00 GMT 2001


On Sun, Feb 11, 2001 at 10:44:05AM +0100, Dennis Bjorklund wrote:
> Some time ago there was a discussion about packed structs and the fact
> that even if you pack a struct, the size of the struct according to
> sizeof() might not be the sum of the size of all the components.
> 
> Have I summed it up correctly so far?

No.  You can certainly pack a structure such that it has 
no padding whatsoever.  For example, 

	struct __attribute__((packed)) bad_struct
	{
	  char c1;
	  char *cp1;
	  char c2;
	  char *cp2;
	};

If this does not yield a structure of size (sizeof(char*)*2 + 2)
on any architecture, then it is a bug.  It certainly does on my
alpha.


r~



More information about the Gcc mailing list