Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Is this valid C? Date: Thu, 23 Feb 2017 09:55:54 -0800 Organization: None to speak of Lines: 35 Message-ID: References: <87shnab3c5.fsf@bsb.me.uk> <87wpclaoqs.fsf@bsb.me.uk> <4a1d176e-0c60-422e-9eb0-04574b2f32ef@googlegroups.com> <54b54bc1-1f0d-40d8-b87d-5a18e95bb0d0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="17193b87357f3199fd5654843cb49d05"; logging-data="22580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/65SpZaq1p4IF0ldstrEqU" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:N9v2qodzWblHZ41t+rBywFIyaFc= sha1:RaF4SJNCXaKQRhpjFwfUnHUlXCU= Xref: csiph.com comp.lang.c:104511 supercat@casperkitty.com writes: > On Thursday, February 23, 2017 at 11:11:06 AM UTC-6, Keith Thompson wrote: >> N1570 6.3.2.1p3, which specifies the conversion of array expressions to >> pointer expressions, says "If the array object has register storage >> class, the behavior is undefined." There is no constraint violation >> (unless I'm missing something). Evaluating the expression `arr` would >> have undefined behavior, but since the expression is never actually >> evaluated, there is no behavior, defined or not. (IMHO it would make >> sense for the expression `arr` to be a constraint violation, but that's >> not what the standard says.) > > What would you think of the idea that a quality implementation should > process an expression like arr[n] in the natural sensible fashion > regardless of whether it would usefully process any other form of > expression that would take the address of "arr"? [...] That isn't what I was talking about, but I'll answer anyway. I think that the [] operator is defined in terms of the & and + operators, and breaking that equivalence for the sake of an obscure and useless corner case would be a bad idea. Of course compiler implementers are free to implement an extension that does that, but my personal preference would be for them to spend their time doing something more useful. I also think that the diagnostic message for an attempt to index a register-qualified array should advise removing the useless "register" keyword from the array object's definition. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"