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

  1. Xref: sparky comp.std.c++:1893 comp.std.c:3255
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!gatech!emory!gwinnett!amfent!amf
  3. From: amf@amfent.Gwinnett.COM (Andy Feibus)
  4. Newsgroups: comp.std.c++,comp.std.c
  5. Subject: Re: Question about sizeof in C/C++.
  6. Message-ID: <cuX5VB1w164w@amfent.Gwinnett.COM>
  7. Date: Mon, 21 Dec 92 08:54:59 EST
  8. References: <1992Dec18.021610.24482@nntpd.lkg.dec.com>
  9. Lines: 34
  10.  
  11. Resending this, since my upstream feed seems to be having problems....
  12.  
  13. diamond@jit345.bad.jit.dec.com (Norman Diamond) writes:
  14. > In article <wwJXVB3w164w@amfent.Gwinnett.COM> amf@amfent.Gwinnett.COM (Andy F
  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. > He was asking about the standards, for which (under the condition you state)
  24. > the answer is... yes.
  25. Thanks for quoting me out of context, but he also asked:
  26.  
  27.     I'm asking because I have C++ code that relies on this.
  28.     It works on Suns but is it portable?
  29.  
  30. And that was the question I answered.
  31.  
  32. > >Different compilers see &ps[k] differently; use parentheses to clarify:
  33. > > &(ps[k]).
  34. > Even K&R-1 and Stroustrop-1 prohibited seeing this expression differently.
  35. That's nice in theory, but I've found at least one UNIX-based compiler 
  36. that interprets it differently.  Since his question was about 
  37. portability, I told him what to do to make sure it worked on 
  38. whatever compiler he chose.  Of course it's not standard, but
  39. complying with the standard and being portable can sometimes be
  40. two very different animals.
  41.  
  42. -- Andy.
  43. andyfe@utoday.com
  44.  
  45.