home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.std.c++:1839 comp.std.c:3233
- Newsgroups: comp.std.c++,comp.std.c
- 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
- From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
- Subject: Re: Question about sizeof in C/C++.
- Message-ID: <1992Dec18.021610.24482@nntpd.lkg.dec.com>
- Sender: usenet@nntpd.lkg.dec.com (USENET News System)
- Reply-To: diamond@jit.dec.com (Norman Diamond)
- Organization: Digital Equipment Corporation Japan , Tokyo
- References: <jamesc.724544278@bart> <wwJXVB3w164w@amfent.Gwinnett.COM>
- Date: Fri, 18 Dec 1992 02:16:10 GMT
- Lines: 23
-
- In article <wwJXVB3w164w@amfent.Gwinnett.COM> amf@amfent.Gwinnett.COM (Andy Feibus) writes:
- >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)
- >Assuming that you [cm]alloc enough memory for ps to support accessing the
- >k'th element of it, the answer is... no.
-
- He was asking about the standards, for which (under the condition you state)
- the answer is... yes.
-
- >Different compilers see &ps[k] differently; use parentheses to clarify:
- > &(ps[k]).
-
- Even K&R-1 and Stroustrop-1 prohibited seeing this expression differently.
- Parenthesization is nice for human readers so that we don't have to look it
- up all the time, but not necessary for C or C++ compilers.
- --
- Norman Diamond diamond@jit081.enet.dec.com
- If this were the company's opinion, I wouldn't be allowed to post it.
- "It's been a lovely recession."
-