Compiler Error?

Michael Greim greim at sbsvax.UUCP
Wed Feb 15 04:03:06 AEST 1989


This is about pre-ANSI C.

Consider the following program:

------ cut -------------------
# include <stdio.h>

main ()
{
	int i, j, k;
	i = 5;
	j = 0;
	k = 0;
	if (i == 5)
		(j = 2) ? k = 3 : 4;
	printf ("j = %d, k = %d\n", j, k);
}
------- cut -----------------

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)

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

SIEMENS SINIX v2.1 finds an error.

Is it really a compiler error? In all the major compilers?
And nobody has noticed it yet? :-)
Is it a typical pcc error?
How does GNU perform?
What about the ANSI compilers?

	-mg

PS.: I found such a statement in GNU grep, when I was porting it to SINIX.
-- 
email : greim at sbsvax.informatik.uni-saarland.dbp.de
  (some mailers might not like this. Then use greim at sbsvax.uucp)
  or  : ...!uunet!unido!sbsvax!greim
# include <disclaimers/std.h>



More information about the Comp.lang.c mailing list