Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!boingo.med.jhu.edu!haven.umd.edu!mimsy!midway!msuinfo!convex.cl.msu.edu!jap From: jap@convex.cl.msu.edu (Joe Porkka) Newsgroups: comp.lang.c Subject: Re: Little problem with sizeof on PC Message-ID: <1991Apr23.132612.16687@msuinfo.cl.msu.edu> Date: 23 Apr 91 13:26:12 GMT References: <1991Apr23.022057.29511@ux1.cso.uiuc.edu> Sender: news@msuinfo.cl.msu.edu Organization: Michigan State University Lines: 36 allender@ux1.cso.uiuc.edu (Mark Allender) writes: >I'm having a litle problem that I have a suspicision about, but want >to clarify. Here's the situation.... >I have a structure that is defined like: >struct header { > int version[2]; > char unused[40]; > int stuff[8]; > char bogus; > char mode; > int time; > char unused2[90]; > char filler[38]; > char filler2[15] ^^^^^^^^^^^^^^^^^^^^^^^^^ > float number; >}; >The total size of the structure is 201 bytes (count it if you wish....). >Now, I want to read the beginning of a binary file into this structure, >so I do something like this: The compiler probly is inserting the pad byte after filler2, to bring "number" to an even address. If you really want to have a file with this info in bnary form, then you will need to write the while 202 bytes, and read the while 202 bytes, including the pad byte imbedded within the structure (or do it member by member). If you want your programs data file to be at all portable, then you will have to use something the the XDR (external data representation) library, or write the data in ASCII form.