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

  1. Xref: sparky comp.std.c++:1906 comp.std.c:3264
  2. Newsgroups: comp.std.c++,comp.std.c
  3. Path: sparky!uunet!microsoft!hexnut!jimad
  4. From: jimad@microsoft.com (Jim Adcock)
  5. Subject: Re: Question about sizeof in C/C++.
  6. Message-ID: <1992Dec24.001540.30000@microsoft.com>
  7. Date: 24 Dec 92 00:15:40 GMT
  8. Organization: Microsoft Corporation
  9. References: <jamesc.724544278@bart> <wwJXVB3w164w@amfent.Gwinnett.COM>
  10. Lines: 17
  11.  
  12. jamesc@swapsdev.state.state.COM.AU (James Cribb) writes:
  13. | Given
  14. |     struct Something*  ps;
  15. |     unsigned  k;
  16. | do the C or C++ standards guarantee that
  17. |     &ps[k] == ((char*) ps) + k * sizeof(struct Something)
  18.  
  19. No.  The relationship holds only if k is chosen such that k is greater
  20. than or equal to zero [true since k unsigned], and k is less than or equal 
  21. to the number of elements in the array pointed-to by ps, assuming ps 
  22. points at a valid array of type Something, and in C++ assuming that 
  23. that operator& isn't user-defined on struct [class] Something....
  24.  
  25. Did I miss anything?
  26.