Path: csiph.com!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:11:11 -0800 Organization: None to speak of Lines: 46 Message-ID: References: <87shnab3c5.fsf@bsb.me.uk> <87wpclaoqs.fsf@bsb.me.uk> <4a1d176e-0c60-422e-9eb0-04574b2f32ef@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="U2FsdGVkX19jIW55ROkz4yhhnFArBxiF" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ZF/ymCC7Wq/bno0XfffKUcGqJEw= sha1:oPb9sVndP9IzolH0JLXjz6yf8aA= Xref: csiph.com comp.lang.c:104508 Tim Rentsch writes: > supercat@casperkitty.com writes: >> the Standard requires implementations to accept code which >> attempts to access members of register-qualified arrays, > > No, it doesn't. Implementations are free to reject any > program that has an expression where an array type would > be converted to the corresponding pointer type, even if > that code could never be executed. That doesn't agree with my reading of the standard. An example: int main(void) { if (0) { register char arr[1]; arr; } } 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.) (FWIW, gcc treats this as a fatal error, while clang merely warns "expression result unused".) I believe the same reasoning applies to this: int main(void) { if (0) { 1/0; } } -- 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"