Problem with #define'd macro...
Steve Emmerson
steve at groucho.ucar.edu
Fri Apr 5 00:41:43 AEST 1991
In <18200 at crdgw1.crd.ge.com> volpe at camelback.crd.ge.com (Christopher R Volpe)
writes:
>|>|>>>#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.
Whoops! Hang on a second!
I said the expression was valid according to the K&R1 grammar. It is,
however, quite invalid under Standard C: it cannot be generated from
the grammar.
The original question was in the context of K&R1 C.
Steve Emmerson steve at unidata.ucar.edu ...!ncar!unidata!steve
More information about the Comp.lang.c
mailing list