Compiler Error?

Mike Haertel mike at thor.stolaf.edu
Fri Feb 17 12:19:49 AEST 1989


In article <683 at sbsvax.UUCP> greim at sbsvax.UUCP (Michael Greim) writes:
>Consider the following program:
...
>		(j = 2) ? k = 3 : 4;
...
>According to the C books I could get my hands on,
>"?:" has higher precedence than the assignment operators, like
>"=" for instance. (In X3J11 too)
>
>Thus the compiler should find an error in the statement, something
>like "misplaced assignment".

No.  That this works is not an error.  Precedence rules are used
to resolve ambiguity about which of two neighboring operators
an expression belongs to.  In this case, the assignment statement
is in the middle of an operator, so to speak, so there is no
ambiguity.

>PS.: I found such a statement in GNU grep, when I was porting it to SINIX.

Don't send a bug report about GNU grep because I won't change it just for
the benefit of some brain damaged compiler without a proper parser.

	Mike Haertel



More information about the Comp.lang.c mailing list