[lug] OFF: sizeof structs in gcc?

D. Stimits stimits at idcomm.com
Thu Jun 7 13:11:13 MDT 2001


"Scott A. Herod" wrote:
> 
> Hello,
> 
> This is a kind of off topic but I'm hoping to avoid the gcc lists.
> 
> Is it true that gcc allocates space for objects/stucts in 4 byte
> words?  Is there a way to avoid this?
> 
> Looks like winder's VC has a "#pragma pack" that can compact objects
> but gcc seems to have nothing comparable.  It's not really a problem.
> That's what bcopy is for.  I'm mainly just curious.
> 
> Thanks,
> 
> Scott Herod

I'd make some guesses on this, but definitely don't consider it a fact.
One guess is that that the x86 address pointer is 32 bit, and it is 4
bytes in order to point at the address of start. The other guess might
be that it is done to keep structs aligned on 32 bit
boundaries...packing could have some really bad performance penalties if
not (at least on x86), such as randomly packing the start of a 7 byte
struct right after a 5 byte struct. Out of curiosity, are you trying to
avoid a lot of memory use where you can't afford to waste memory?

D. Stimits, stimits at idcomm.com



More information about the LUG mailing list