Little problem with sizeof on PC

Joe Porkka jap at convex.cl.msu.edu
Tue Apr 23 23:26:12 AEST 1991


allender at 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.



More information about the Comp.lang.c mailing list