🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1125

Re: Question about sizeof in C/C++.

#1125
From: Norman Diamond
Date: Mon, 21 Dec 1992 10:38
20 lines
1778 bytes
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."
Technical Details
Message-ID: <BzLuvz.AC7@jrd.dec.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!decuac!pa.dec.com!e2big.mko.dec.com!jrdzzz.jrd.dec.com!jit533.jit.dec.com!diamond
References: <1992Dec3.195422.26393@cs.brown.edu> <1992Dec07.230924.20465@microsoft.com> <jamesc.724544278@bart> <jamesc.724907666@bart>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++,comp.std.c
Path: arc1-ca.pugleaf.net!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