Article View: comp.std.c
Article #4267Re: Comma operator in constant expression
From: Christopher R. Volpe
Date: Mon, 23 Oct 1995 14:01
Date: Mon, 23 Oct 1995 14:01
90 lines
4281 bytes
4281 bytes
In article <Pine.ULT.3.91.951020212504.26923A-100000@mars.dsv.su.se>, Jens M Andreasen <jens-and@dsv.su.se> writes: > > >On 20 Oct 1995, Christopher R. Volpe wrote: > >> >A constant is permitted, right? >> >> Yep. Too bad we don't have one. > >My point is that we do not have anything but alfabetsoup before >evaluation. Wrong. We have syntactic categories before we have numerical evaluation. >You are expecting a compiler to know the meaningfulness >of random characters without letting it actually read it ? No. You are the one doing that. You are expecting the compiler to evaluate expressions to yield numeric values before analyzing the legality of the syntact construct in the context in which it occurs. > Then by what >method shall we find the hidden comma expression (Or any other doubtful >expression, including the works of Shakespeare)? Intuitively, but in no >way proven, this would involve parsing of a yet unknown nature. > >Or to put it another way: At what time of compile are we going to tell >the user that his code is way off? > >1) When we know what it means. > >2) Before we know what it means. As soon as a syntax error or constraint violation is discovered. And in this cast the presence of a comma-expression where a constant expression is required is a constraint violation, and this is detected before the compiler even attempts to evaluate the expression. > >This Is important since the expression we are discussing changes >drastically after evaluation. Not quite sure what this means, but evaluation doesn't change the syntactic structure of a piece of code. (Preprocessing can do that, but that's not what we're talking about here.) > >You found the comma, and you realized that it did not belong there. This >is fantastic (no sarkasm here, I do believe life is beutiful) but I can't >see any way of formalising this general ability into a machine method. What on earth are you talking about? The parser parses an expression first. It reduces a comma expression non-terminal symbol as part of the parsing process. When it does this is sets a little flag that says "I no longer have a constant expression", which gets propagated up the parse tree all the way up to "initializer", where the constraint violation is detected. Do you really think that it is impossible for the compiler to *know* that there is a comma in that expression before that expression is evaluated? > >And the point here is that we are not only discussing a single special >case, but also trying to cope with empty statements in general. I couldn't understand the above remark. Where did "empty statements" come into the picture? > >If this means that the wordings must be slightly changed to fit reality Whose reality? >then please go ahead, but as I see it, it is matter of *when* the >standard is to be consulted rather than how, where all we seems to agree >upon is that at least it should be after opening the file. Opening what file? As for *when* the standard is to be consulted, the answer is clear: The Standard is to be consulted any time there is a question or dispute over the legality of a programming construct, the meaning of a programming construct, or the conformance of an implementation that behaves in a particular way in response to a particular programming construct. -- Chris Volpe Phone: (518) 387-7766 (Dial Comm 8*833 GE Corporate R&D Fax: (518) 387-6560 PO Box 8, Schenectady, NY 12301 Email: volpecr@crd.ge.com
Technical Details
Message-ID:
<46g785$8p7@rdsunx.crd.ge.com>Path:
arc1-ca.pugleaf.net!bart.crd.ge.com!volpeReferences:
<45uevf$d99@news0.rain.rg.net> <Pine.ULT.3.91.951017124752.2343A-100000@mars.dsv.su.se> <464s1t$lb4@usenet.pa.dec.com> <Pine.ULT.3.91.951019204530.7241B-100000@mars.dsv.su.se> <4685n3$l8k@rdsunx.crd.ge.com> <Pine.ULT.3.91.951020212504.26923A-100000@mars.dsv.su.se>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!bart.crd.ge.com!volpe From: volpe@bart.crd.ge.com (Christopher R. Volpe) Newsgroups: comp.std.c Subject: Re: Comma operator in constant expression Date: 23 Oct 1995 14:01:41 GMT Organization: GE Corporate Research & Development Sender: volpe@bart (Christopher R. Volpe) Distribution: world Message-ID: <46g785$8p7@rdsunx.crd.ge.com> References: <45uevf$d99@news0.rain.rg.net> <Pine.ULT.3.91.951017124752.2343A-100000@mars.dsv.su.se> <464s1t$lb4@usenet.pa.dec.com> <Pine.ULT.3.91.951019204530.7241B-100000@mars.dsv.su.se> <4685n3$l8k@rdsunx.crd.ge.com> <Pine.ULT.3.91.951020212504.26923A-100000@mars.dsv.su.se> Reply-To: volpe@ausable.crd.ge.com NNTP-Posting-Host: bart.crd.ge.com