Correct parsing of ternary operator.

Mike Lijewski lijewski at batcomputer.tn.cornell.edu
Thu Jan 4 10:21:31 AEST 1990


Consider the following code:

main()
{
    int a = 0, b = 1, c = 2;

    c ? c = a : c = b;
    exit(0);
}

According to the precedence rules of C, the conditional expression
should be evaluated as:

	 (c ? c = a : c) = b;

which should produce and error.  Well, it happens that I have a
compiler which accepts this and produces results which suggest
to me that it is evaluating this expression as:

	 c ? c = a :(c = b);

The vendor seems unwilling to accept this as a bug.  Am I just being
pedantic, or is this a serious bug?  I haven't been able to come up
with an example of correct usage of the ternary operator, which 
produces incorrect code.  If anyone knows of some code which might
clearly prove that this is a bug, I would sure appreciate receiving it.
Thanks.


-- 
Mike Lijewski  (H)607/277-7623 (W)607/255-0539 (desk)607/255-2960
Cornell National Supercomputer Facility
ARPA: mjlx at cornellf.tn.cornell.edu  BITNET: mjlx at cornellf.bitnet
SMAIL:  1122 Ellis Hollow Rd. Ithaca, NY  14850



More information about the Comp.lang.c mailing list