home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.std.c++:1880 comp.std.c:3247
- Newsgroups: comp.std.c++,comp.std.c
- Path: sparky!uunet!haven.umd.edu!decuac!pa.dec.com!e2big.mko.dec.com!jrdzzz.jrd.dec.com!jit533.jit.dec.com!diamond
- From: diamond@jit533.jit.dec.com (Norman Diamond)
- Subject: Re: Question about sizeof in C/C++.
- Message-ID: <BzLuvz.AC7@jrd.dec.com>
- Sender: usenet@jrd.dec.com (USENET News System)
- Nntp-Posting-Host: jit533.jit.dec.com
- Reply-To: diamond@jit.dec.com (Norman Diamond)
- Organization: Digital Equipment Corporation Japan , Tokyo
- References: <1992Dec3.195422.26393@cs.brown.edu> <1992Dec07.230924.20465@microsoft.com> <jamesc.724544278@bart> <jamesc.724907666@bart>
- Date: Mon, 21 Dec 1992 10:38:23 GMT
- Lines: 20
-
- In article <jamesc.724907666@bart> jamesc@swapsdev.state.state.COM.AU (James Cribb) writes:
- >Suppose a single struct Something needed 7 bytes of memory. For word
- >alignment, these might need to start on, say, 4-byte boundaries.
- >Do the standards guarantee that sizeof(struct Something) will always be
- >8 rather than 7?
-
- Yes. ANSI's original C standard section 3.5.2.1, page 62 lines 2 to 3:
- "Each non-bit-field member of a structure or union object is aligned in an
- implementation-defined manner appropriate to its type." Lines 13 to 14:
- "There may also be unnamed padding at the end of a structure or union, as
- necessary to achieve the appropriate alignment were the structure or union
- to be an element of an array."
-
- If it is appropriate for a member type to be aligned on a 4-byte boundary,
- then the implementation-defined manner will result in such alignment,
- including if necessary a padding byte at the end of the structure.
- --
- Norman Diamond diamond@jit081.enet.dec.com
- If this were the company's opinion, I wouldn't be allowed to post it.
- "It's been a lovely recession."
-