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: C Macros Badly Defined? Date: Wed, 31 May 2017 09:36:56 -0700 Organization: None to speak of Lines: 70 Message-ID: References: <8760h28iep.fsf@bsb.me.uk> <87tw4m6sbd.fsf@bsb.me.uk> <32478449-75f4-44d0-bcb0-b159bc1b8473@googlegroups.com> <20170530191233.84e5575b78503611c757e526@gmail.com> <24fcaf3b-5a4a-46ad-ad65-ad7ab3e23c66@googlegroups.com> <5a862af8-50eb-443c-8562-a3ae8e9cd9da@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="711dc6a62429d49ca6324d543e118187"; logging-data="28531"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZeMbY7+vrOLHPo3AeCfH5" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:X69kFOo3FL4MAThk0JEGEn5VrdU= sha1:WK/fysjK9K/jbkEBHlffP2A+Vfo= Xref: csiph.com comp.lang.c:111023 supercat@casperkitty.com writes: > On Tuesday, May 30, 2017 at 7:12:08 PM UTC-5, Keith Thompson wrote: >> supercat writes: >> > Most standards specify what conforming entities have to "do", and >> > are quite specific about what entities are responsible for ensuring >> > what. The Standard sometimes talks about obligations of programs >> > or implementations, but sometimes uses "shall be" to impose >> > obligations upon grammatical constructs. >> >> For example? > > Compare 6.2.5p3: > > If any other character is stored in a char object, the resulting value > is implementation-defined but shall be within the range of values that > can be represented in that type. (which is outside a constraint) > with 6.8.4.2p2: > > If a switch statement has an associated case or default label within > the scope of an identifier with a variably modified type, the entire > switch statement shall be within the scope of that identifier. (which is within a constraint) > The former could be interpreted to suggest that if an implementation > defined CHAR_MIN as -127 but specified that values get two's-complement > reduced, a program which stored 128 to a "char" and read it back would > violate a "shall" constraint and thus have Undefined Behavior. I think it's a misuse of the word "shall". Replacing "shall" by "is guaranteed to" would be an improvement. (BTW, your use of the word "constraint" here is inconsistent with the way the standard uses it.) > The > latter could be read as suggesting that an implementation shall treat > the scopes of identifiers in such fashion as to abide by the second. Except that that interpretation would contradict other requirements about scopes of identifiers. I think it's clear enough that a constraint is being imposed on programs. This program: int main(void) { int n = 1; switch (n) { case 1: ; int vla[n]; default: ; } } violates that constraint, requiring a diagnostic. > Both constructs can be worked out, of course, but especially with the > second I think it would be clearer to say that no "case" label shall > be placed within the scope of a variably-modified type *unless* the > entire switch statement is likewise within that scope. Sure, that's another way to express the same requirement. (And yet again, please use shorter lines so I don't have to reformat quoted text.) -- 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"