Compiler Error?

Gertjan van Oosten gjoost at westc.UUCP
Thu Feb 16 21:30:13 AEST 1989


In article <683 at sbsvax.UUCP> greim at sbsvax.UUCP (Michael Greim) writes:
>Consider the following program:
...
>		(j = 2) ? k = 3 : 4;
...
>On 43BSD, SunOS 3.4, ULTRIX 2.0 this compiles with no error.
>
>According to the C books I could get my hands on,
>"?:" has higher precedence than the assignment operators, like
>"=" for instance. (In X3J11 too)

Your quote from the C-books is right, but you should read it more
carefully:
	"?:" has higher precedence than assignment.
	  ^
	  +--- spot the colon there!

So this means, that an expression like:
	a = b ? c : d
is parsed as:
	a = (b ? (c) : d)
"?:" is a ternary operator, with operands b, c and d (assuming that
b and d don't contain unparenthesised expressions containing lower
precedence operators).

>Thus the compiler should find an error in the statement, something
>like "misplaced assignment".

No, it shouldn't.

>SIEMENS SINIX v2.1 finds an error.

Siemens SINIX v2.1 is an error. :-)

               Yours sincerely,

			   G. J. van Oosten.

"Peace on earth and mercy mild, Mother Brown has lost her child.
 Just another forgotten son....."
	Marillion, "Forgotten Sons"



More information about the Comp.lang.c mailing list