Article View: comp.sys.ibm.pc
Article #42308Re: TC bug in sizeof()?
From: Duncan Murdoch
Date: Thu, 15 Feb 1990 20:25
Date: Thu, 15 Feb 1990 20:25
22 lines
1262 bytes
1262 bytes
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
Technical Details
Message-ID:
<1522@maytag.waterloo.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!mailrus!iuvax!maytag!watstat!dmurdochReferences:
<1519@maytag.waterloo.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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