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

  1. Xref: sparky comp.std.c++:1830 comp.std.c:3227
  2. Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!olivea!charnel!rat!usc!howland.reston.ans.net!europa.asd.contel.com!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: <wwJXVB3w164w@amfent.Gwinnett.COM>
  7. Date: 17 Dec 92 14:10:55 GMT
  8. References: <jamesc.724544278@bart>
  9. Lines: 18
  10.  
  11. jamesc@swapsdev.state.state.COM.AU (James Cribb) writes:
  12. > Given
  13. >     struct Something*  ps;
  14. >     unsigned  k;
  15. > do the C or C++ standards guarantee that
  16. >     &ps[k] == ((char*) ps) + k * sizeof(struct Something)
  17. > I'm asking because I have C++ code that relies on this.
  18. > It works on Suns but is it portable?
  19. Assuming that you [cm]alloc enough memory for ps to support accessing the
  20. k'th element of it, the answer is... no.  Different compilers see &ps[k]
  21. differently; use parentheses to clarify: &(ps[k]).
  22.  
  23. -- Andy.
  24. andyfe@utoday.com
  25.