sizeof struct

mark.a.hartman hartman at cbnewsc.ATT.COM
Wed Sep 6 13:37:32 AEST 1989


In article <29722 at pbhya.PacBell.COM> afh at PacBell.COM (Alan Hobesh) writes:
>
>
>The following c code prints the size of the definded structure to be 44,
>when compiled on an AT&T 3B20 running UNIX V5.2.1.
>

... structure and code omitted ...

>
>However, when the code is downloaded to a PC and compiled using Turbo C,
>the size of the structure is reported to be 42.
>
>Why is there a difference and which is the correct size?

The AT&T 3B20 compiler rounds structures up to an even word length,
in your case from 42 bytes to 44.  If you need code that is portable
between the two machines, try adding something like

	char	fill[2];

to the end of the structure to fill it out.  Then, "sizeof struct"
will be the same on both machines.

-- 
Mark Hartman                     hartman at ihlpm.att.com
                                 ..att!ihlpm!hartman
#include <std_disclaimer.h>



More information about the Comp.lang.c mailing list