home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / cplus / 1880 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.8 KB

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