Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!jarthur!nntp-server.caltech.edu!seismo.gps.caltech.edu!bruce From: bruce@seismo.gps.caltech.edu (Bruce Worden) Newsgroups: comp.lang.c Subject: Re: ** help... Summary: pad those pups out Message-ID: <1990Aug30.191533.20589@laguna.ccsf.caltech.edu> Date: 30 Aug 90 19:15:33 GMT References: <2409@dsacg2.dsac.dla.mil> <1884@jura.tcom.stc.co.uk> <11245@crdgw1.crd.ge.com> <1912@islay.tcom.stc.co.uk> Sender: bruce@seismo.gps.caltech.edu (Bruce Worden) Organization: California Institute of Technology, CA Lines: 44 In article <1912@islay.tcom.stc.co.uk> rmj@htc1.UUCP (Rhodri James) writes: [material deleted] >The crux of the potential health hazard comes with the definition of >sizeof, which K&R2 says (section 6.3) gives a size_t result equal to the >size of the specified object or type in bytes. Nothing here guarentees >that the *end* of the object will be such that another object straight >after it in memory (which is what the multiplication implies) will be >correctly aligned. Many structs would give appropriately odd lengths; >I'm sure you don't need examples. Actually, examples would be nice, since I don't see what you mean. On a machine requiring alignment: struct thingy { char a; } sizeof(struct thingy) is 1. struct thingy { int i; /* four byte ints */ } sizeof(struct thingy) is 4. struct thingy { int i; char a; } sizeof(struct thingy) is 8. The structure is padded to insure that alignment is maintained. > ... Can anyone >quote chapter and verse invalidating this argument (please)? I don't know what the standard says about the issue (if anything), but it is difficult to imagine a serious vendor shipping a system that required more than single byte alignment and in which the structure in the last example was size 5. It is not so much a question of the standard, but, rather, one of functionality. -------------------------------------------------------------------------- C. Bruce Worden bruce@seismo.gps.caltech.edu 252-21 Seismological Laboratory, Caltech, Pasadena, CA 91125