Xref: utzoo comp.sys.ibm.pc:44492 comp.lang.c:25952 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!mailrus!iuvax!maytag!watstat!dmurdoch From: dmurdoch@watstat.waterloo.edu (Duncan Murdoch) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: TC bug in sizeof()? Message-ID: <1522@maytag.waterloo.edu> Date: 15 Feb 90 20:25:28 GMT References: <1519@maytag.waterloo.edu> Sender: daemon@maytag.waterloo.edu Reply-To: dmurdoch@watstat.waterloo.edu (Duncan Murdoch) Organization: U. of Waterloo, Ontario Lines: 22 In article <1519@maytag.waterloo.edu> I asked: > >As illustrated in the program below, if a structure is an odd size, and >is compiled with Word alignment, the sizeof function rounds the size up >one byte. > >Is this a bug? Thanks to several people who told me that it isn't a bug, but a necessary property so that relations like sizeof(array) = sizeof(element)*(number of elements) hold. One more question then: Originally this came up because my friend wanted to read fixed (odd) sized records from a file, using while (fread(&structure,sizeof(structure),1,data)!=0) { ... } Obviously sizeof() isn't the right thing to use here. What's the recommended way to declare that a structure is "packed", and find out its packed size? Duncan Murdoch