sizeof struct

Doug Gwyn gwyn at smoke.BRL.MIL
Wed Sep 6 20:06:17 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.
[...]
>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?

Both sizes are correct.  The difference is due to structure padding
(probably at the end of the structure, in this particular case).
C implementations differ in the amount and location of such padding.
If you intended the structure to describe an externally-imposed data
format, you need to be aware that there may be padding between the
structure members as well as at the end, so a simple roll-in of the
data into such a structure variable may not work right.



More information about the Comp.lang.c mailing list