Problem with #define'd macro...

Christopher R Volpe volpe at camelback.crd.ge.com
Thu Apr 4 02:28:52 AEST 1991


In article <18146 at crdgw1.crd.ge.com>, volpe at camelback.crd.ge.com
(Christopher R Volpe) writes:
|>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. 

Steve Emmerson pointed out to me that the above expression is
perfectly legal because the grammar in both K&R1 and K&R2  prevent
parsing the ?: operator as the lhs of the assignment, thus precedence
doesn't apply. (I put too much faith in Table 2.1). BTW, both
GCC and SunOS cc get this completely wrong. They complain about invalid lhs
of assignment.

Thanks, Steve.

-Chris
                                                           
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com



More information about the Comp.lang.c mailing list