Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Offsetof with array elements Date: Tue, 18 Feb 2020 01:43:22 -0800 Organization: A noiseless patient Spider Lines: 27 Message-ID: <86y2t0dydh.fsf@linuxsc.com> References: <0150dd64-4217-49bc-88d0-e8f8925a9dd2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="d9b0a35ddf05bf8591aa2d3738ff843a"; logging-data="14319"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zKxXiH5OPDg7IKc+b1dSfnPobHwHGXAc=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:RJcETCsxr5rwMLu08iZknqhOdoI= sha1:rQ82UOkW95LHicvjeX/i+QVgiaY= Xref: csiph.com comp.lang.c:150070 James Kuyper writes: > On 2/11/20 1:24 PM, Manfred wrote: > >> On 2/11/2020 6:46 PM, David Brown wrote: >> >>> On 11/02/2020 17:32, James Kuyper wrote: >>> >>>> "The array-subscript [ ] operator ... may be used in the creation of >>>> an address constant, but the value of an object may not be accessed by >>>> the use of [that] operator." (6,6p9). >>> >>> Right. So since the expression "offsetof(struct S, a[i])" has to access >>> the object "i" in order to calculate the address (or the offset, in this >>> case), it is disallowed? >> >> It sound to me like this part says the address constant creation /is/ >> allowed, since the object is not accessed, i.e. its address is not >> dereferenced. > > The relevant object is "i", not S. And it's the value of the object, not > it's address, which, if accessed, violates that rule. The value stored > in 'i' is needed to determine that offset, so this construct does > violate that rule. It isn't the use of [] that accesses an object. It is the lvalue conversion of 'i' that accesses an object.