From -1046506715272375968
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1149ec,c0f8f764e8b7d30f
X-Google-Attributes: gid1149ec,public
X-Google-Thread: f78e5,c0f8f764e8b7d30f
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-12-19 15:59:34 PST
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."


