Article View: comp.sys.ibm.pc
Article #42314Re: TC bug in sizeof()?
From: Barry.True
Date: Fri, 16 Feb 1990 14:03
Date: Fri, 16 Feb 1990 14:03
24 lines
1502 bytes
1502 bytes
In article <1519@maytag.waterloo.edu> dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:
>
>[Stuff deleted about asking whether it is an error that sizeof rounds the]
>[following structure up one byte when in word but not alignment.]
>
>Sample program:
>
>struct test
> { char a;
> char b;
> char c;
> } structure;
>
IMHO (since I don't know that much about TC) the fact that you used word
alignment means that the compiler is going to try to align all multi-byte
data on a word boundary (i.e., four bytes). Since the above structure is
only three bytes long it is padded with an extra byte when stored so the
next data element will be aligned on an even word boundary. We used to have
the same problem with the C compiler on a SYSVR0 system running on an AT&T
3B5 system. I'm not sure if you will run into any problems using the length
return from sizeof(struct test) in something like strncpy() or memcpy() to
initialize the structure or not since you won't be overwriting into another
variable's data space. Any body else know?
Technical Details
Message-ID:
<226@emdeng.Dayton.NCR.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!ncrlnk!emdeng!btrueReferences:
<1519@maytag.waterloo.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!ncrlnk!emdeng!btrue From: btrue@emdeng.Dayton.NCR.COM (Barry.True) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: TC bug in sizeof()? Message-ID: <226@emdeng.Dayton.NCR.COM> Date: 16 Feb 90 14:03:48 GMT References: <1519@maytag.waterloo.edu> Reply-To: btrue@emdeng.UUCP (Barry.True) Organization: NCR, E&M Dayton Lines: 24