Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!uakari.primate.wisc.edu!aplcen!ginosko!uunet!philmtl!ray From: ray@philmtl.philips.ca (Raymond Dunn) Newsgroups: comp.lang.c Subject: Re: sizeof struct Keywords: sizeof struct Message-ID: <692@philmtl.philips.ca> Date: 8 Sep 89 00:34:21 GMT References: <29722@pbhya.PacBell.COM> <10945@smoke.BRL.MIL> Reply-To: ray@philmtl.philips.ca (Raymond Dunn) Organization: Philips Electronics Ltd. - St. Laurent P.Q., Canada Lines: 29 In article <10945@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: >In article <29722@pbhya.PacBell.COM> afh@PacBell.COM (Alan Hobesh) writes: >>Why is there a difference [of sizes of struct on different machines] > >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. In MS 'C' the compiler can be made to pack structures tightly, at the expense of the code space and execution time required to access the fields in a less efficient manner. In MSC 4.x, use the /Zp option switch. (see page 193 of the Users' Guide). In MSC 5.x, use the /Zpn option switch or #pragma pack(n), where n defines 1, 2 or 4 byte boundaries. (see page 100 of the Users' Guide). Whether or not it's proper to use such language extensions to handle externally imposed data formats is a discussion I'd rather not breach.... -- Ray Dunn. | UUCP: ..!uunet!philmtl!ray Philips Electronics Ltd. | TEL : (514) 744-8200 Ext: 2347 600 Dr Frederik Philips Blvd | FAX : (514) 744-6455 St Laurent. Quebec. H4M 2S9 | TLX : 05-824090