Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c Subject: Re: sizeof(struct) and padding Message-ID: <14309@goofy.megatest.UUCP> Date: 25 Oct 90 03:49:44 GMT References: <1229@sun13.scri.fsu.edu> Organization: Megatest Corporation, San Jose, Ca Lines: 15 From article <1229@sun13.scri.fsu.edu>, by mayne@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.