Article View: comp.std.c
Article #4250Re: Comma operator in constant expression
From: Jens M Andreasen
Date: Thu, 19 Oct 1995 20:24
Date: Thu, 19 Oct 1995 20:24
38 lines
2182 bytes
2182 bytes
static int i = 1 ? 3 : ( 1, 2);
On 19 Oct 1995, Norman Diamond wrote:
> No, after parsing the expression, the compiler ends up with something like:
> 1 ? 3 : (1, 2);
1 The programmer tells that the condition is always thrue. So there is no
? condition left for the compiler to evaluate? Fine, then don't! At this
stage the ? operator is reduced to an elegant illusion.
3 This constant is for real.
:
( Start of parenthesis, hmmm , interresting ...
1 Now, what to do with this? Consider it done and gone .
, (and this cute little comma goes down the drain as well :)
2 This constant would have been the value of the parenthesized expression
) if the condition had been explicitly false.
So at this stage the compiler will be left with one welldefined constant.
It did not even have to compute it ...
> The question is not the result of evaluating the expression, the question is
> whether the expression is permitted. ...
---------------------------------<snip>--------------------------------
A constant is permitted, right?
... but the standard adds a sentence saying that
> implementations can accept additional forms of constant expression. What
> does this nonsense mean?
---------------------------------<snip>--------------------------------
I interprete that as a way of saying that you are allowed to obfuscate
your constants any way you like, as long as they remain constants. There is
nothing in the expression above that could ever be nothing but a constant.
// Jens M Andreasen (representing my private opinion only)
Technical Details
Message-ID:
<Pine.ULT.3.91.951019204530.7241B-100000@mars.dsv.su.se>Path:
arc1-ca.pugleaf.net!mars.dsv.su.se!jens-andReferences:
<45uevf$d99@news0.rain.rg.net> <Pine.ULT.3.91.951017124752.2343A-100000@mars.dsv.su.se> <464s1t$lb4@usenet.pa.dec.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mars.dsv.su.se!jens-and From: Jens M Andreasen <jens-and@dsv.su.se> Newsgroups: comp.std.c Subject: Re: Comma operator in constant expression Date: Thu, 19 Oct 1995 21:24:28 +0100 Message-ID: <Pine.ULT.3.91.951019204530.7241B-100000@mars.dsv.su.se> References: <45uevf$d99@news0.rain.rg.net> <Pine.ULT.3.91.951017124752.2343A-100000@mars.dsv.su.se> <464s1t$lb4@usenet.pa.dec.com> NNTP-Posting-Host: mars.dsv.su.se Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <464s1t$lb4@usenet.pa.dec.com>