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