sizeof(struct) and padding

Dave Jones djones at megatest.UUCP
Thu Oct 25 13:49:44 AEST 1990


>From article <1229 at sun13.scri.fsu.edu>, by mayne at sun10.scri.fsu.edu (William (Bill) Mayne):

> 
> The $64K question is: How do I portably get the actual size of
> a structure without padding when I need that rather than
> what sizeof() tells me?

You don't. When you write structures directly to disc, it is non-portable,
period -- whether or not you write the tail-padding. Different machines will
have different internal padding, even different data formats. For most
kinds of data, text (ASCII or EBCDIC) is the perfect solution. Use fprintf()
or get fancy with a library package. I think there are some public domain
ones. Somebody will also mention Sun's XDR, which may work well for you,
particularly if your machine uses the same data-representations that Sun
machines do.



More information about the Comp.lang.c mailing list