Problem with #define'd macro...
Christopher R Volpe
volpe at camelback.crd.ge.com
Wed Apr 3 00:47:36 AEST 1991
In article <10868 at ncar.ucar.edu>, steve at groucho.ucar.edu (Steve
Emmerson) writes:
|>In <1099 at gtenmc.UUCP> ravim at gtenmc.UUCP (Vox Populi) writes:
|>
|>>In article <1991Mar20.150301.9941 at evax.arl.utexas.edu>
c145gmk at utarlg.uta.edu
|>writes:
|>>>Attempting to compile the following (fragment, but displays the problem)
|>>>results in an 'invalid target for assignment' error on our VAX running
|>
|>>>#define DIV_MOD(d,r,x,y) ( y == 0.0 ? d = 0.0, r = x : d = x/y, r =
x - d*y )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is the root of the
precedence problem because the value "x/y" is
being assigned to the result of the conditional
operator, which is not an lvalue, and therefore
an illegal target for assignment.
|>
|>>>a = 5, b = 2; DIV_MOD(quotient,remainder,a,b);
|>
|>>I think the compiler error that you were getting is because, operator
|>>precedence is not observed here correctly.
|>
|>I believe the above statement is false because
|>
|> 1) the string in question (which is an expression):
|>
|> a == b ? c=d, e=f : g=h, i=j
|>
|> can be generated from the K&R1 grammar; and
Compilers complain about plenty of other things besides strings not being
generated from the grammar. Ever hear of undeclared variables?
|>
|> 2) precedence is irrelevant in determining whether or not a string
|> is valid.
The compiler didn't punt with a parse error, did it? It parsed it
the "wrong" way of the two possible ways (given the grammar and ingoring
the precedence rules.) By "wrong" I mean in terms of what the programmer
wanted. It was right according to the precedence rules. The problem was
not that the syntax was violated, but rather that, because of the
precedence rules, an assignment was made to a non-lvalue.
|>Precedence, on the other hand, is a tool used by parsers to
|>disambiguate between two or more ways of generating the same string
|>from a given grammar. The validity of a given string, however, is
|>determined solely on the basis of whether or not it can be generated by
|>the production rules of the grammar.
Compilers do not compile by syntax alone. The grammar is not a complete
definition of the language.
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com
More information about the Comp.lang.c
mailing list