Article View: comp.sys.ibm.pc
Article #42307TC bug in sizeof()?
From: Duncan Murdoch
Date: Thu, 15 Feb 1990 17:47
Date: Thu, 15 Feb 1990 17:47
29 lines
1134 bytes
1134 bytes
A friend of mine has found something surprising in TC. Neither of us knows
C well enough to know for sure that this is a bug, but it looks like one.
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?
Sample program:
struct test
{ char a;
char b;
char c;
} structure;
main()
{
printf("Size of structure= %d\n",sizeof(structure));
}
This prints a 3 if compiled with byte alignment, an 4 if compiled with word
alignment.
Thanks for any help. Please post to comp.sys.ibm.pc, or email to me, as
you prefer.
Duncan Murdoch
Technical Details
Message-ID:
<1519@maytag.waterloo.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!mailrus!iuvax!maytag!watstat!dmurdochShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!mailrus!iuvax!maytag!watstat!dmurdoch From: dmurdoch@watstat.waterloo.edu (Duncan Murdoch) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: TC bug in sizeof()? Message-ID: <1519@maytag.waterloo.edu> Date: 15 Feb 90 17:47:49 GMT Sender: daemon@maytag.waterloo.edu Reply-To: dmurdoch@watstat.waterloo.edu (Duncan Murdoch) Organization: U. of Waterloo, Ontario Lines: 29