Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!ginosko!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: sizeof struct Keywords: sizeof struct Message-ID: <10945@smoke.BRL.MIL> Date: 6 Sep 89 10:06:17 GMT References: <29722@pbhya.PacBell.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 15 In article <29722@pbhya.PacBell.COM> afh@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.