home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1839 < prev    next >
Encoding:
Internet Message Format  |  1992-12-20  |  1.6 KB

  1. Xref: sparky comp.std.c++:1839 comp.std.c:3233
  2. Newsgroups: comp.std.c++,comp.std.c
  3. Path: sparky!uunet!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!deccrl!news.crl.dec.com!news!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
  4. From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
  5. Subject: Re: Question about sizeof in C/C++.
  6. Message-ID: <1992Dec18.021610.24482@nntpd.lkg.dec.com>
  7. Sender: usenet@nntpd.lkg.dec.com (USENET News System)
  8. Reply-To: diamond@jit.dec.com (Norman Diamond)
  9. Organization: Digital Equipment Corporation Japan , Tokyo
  10. References: <jamesc.724544278@bart> <wwJXVB3w164w@amfent.Gwinnett.COM>
  11. Date: Fri, 18 Dec 1992 02:16:10 GMT
  12. Lines: 23
  13.  
  14. In article <wwJXVB3w164w@amfent.Gwinnett.COM> amf@amfent.Gwinnett.COM (Andy Feibus) writes:
  15. >jamesc@swapsdev.state.state.COM.AU (James Cribb) writes:
  16. >> Given
  17. >>     struct Something*  ps;
  18. >>     unsigned  k;
  19. >> do the C or C++ standards guarantee that
  20. >>     &ps[k] == ((char*) ps) + k * sizeof(struct Something)
  21. >Assuming that you [cm]alloc enough memory for ps to support accessing the
  22. >k'th element of it, the answer is... no.
  23.  
  24. He was asking about the standards, for which (under the condition you state)
  25. the answer is... yes.
  26.  
  27. >Different compilers see &ps[k] differently; use parentheses to clarify:
  28. > &(ps[k]).
  29.  
  30. Even K&R-1 and Stroustrop-1 prohibited seeing this expression differently.
  31. Parenthesization is nice for human readers so that we don't have to look it
  32. up all the time, but not necessary for C or C++ compilers.
  33. --
  34. Norman Diamond       diamond@jit081.enet.dec.com
  35. If this were the company's opinion, I wouldn't be allowed to post it.
  36. "It's been a lovely recession."
  37.