Article View: comp.std.c
Article #4244Re: Comma operator in constant expression
From: Norman Diamond
Date: Thu, 19 Oct 1995 06:43
Date: Thu, 19 Oct 1995 06:43
40 lines
2817 bytes
2817 bytes
In article <Pine.ULT.3.91.951017124752.2343A-100000@mars.dsv.su.se>, Jens M Andreasen <jens-and@dsv.su.se> writes: >On 16 Oct 1995, Paul Long wrote: >> Is an implementation required to generate a diagnostic for this declaration? >> static int i = 1 ? 3 : (1, 2); > After parsing your fancy expression, the compiler ends up with something >like: static i = 3; >Looks legal to me. No, after parsing the expression, the compiler ends up with something like: 1 ? 3 : (1, 2); The question is not the result of evaluating the expression, the question is whether the expression is permitted. And the problem is that the standard requires a diagnostic for violation of a constraint (which this is) and the standard permits implementations to define extensions in cases of undefined behavior (which this is, i.e. the implementation can issue a diagnostic and proceed to compute a value), but the standard adds a sentence saying that implementations can accept additional forms of constant expression. What does this nonsense mean? If the extra sentence means that implementation extensions are permitted in a case of undefined behavior (but not forgetting a diagnostic) then it is a no-op. If the extra sentence means that implementation extensions are permitted in a case of undefined behavior (including forgetting a diagnostic) then it contradicts the part of the standard that requires diagnostics for violations of constraints. I think someone once posted that information had been received from the committee, suggesting that their intention was that the extra sentence override the general rule so that a diagnostic is not required when an implementation extension accepts an otherwise invalid constant expression. This also doesn't make a lot of sense because the committee could have put the restrictions in a semantics paragraph instead of a constraints paragraph, achieving the same result and still not requiring the extra sentence. I think the answer to Mr. Long's question is: No one knows. -- << If this were the company's opinion, I would not be allowed to post it. >> "I paid money for this car, I pay taxes for vehicle registration and a driver's license, so I can drive in any lane I want, and no innocent victim gets to call the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
Technical Details
Message-ID:
<464s1t$lb4@usenet.pa.dec.com>Path:
arc1-ca.pugleaf.net!jrd.dec.com!diamondReferences:
<45uevf$d99@news0.rain.rg.net> <Pine.ULT.3.91.951017124752.2343A-100000@mars.dsv.su.se>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!jrd.dec.com!diamond From: diamond@jrd.dec.com (Norman Diamond) Newsgroups: comp.std.c Subject: Re: Comma operator in constant expression Date: 19 Oct 1995 06:43:09 GMT Organization: DEC Japan Research and Development Center Distribution: world Message-ID: <464s1t$lb4@usenet.pa.dec.com> References: <45uevf$d99@news0.rain.rg.net> <Pine.ULT.3.91.951017124752.2343A-100000@mars.dsv.su.se> NNTP-Posting-Host: jit533.jrd.dec.com