Compiler Error?

Jim Shankland jas at ernie.Berkeley.EDU
Thu Feb 16 03:03:41 AEST 1989


In article <683 at sbsvax.UUCP> greim at sbsvax.UUCP (Michael Greim) writes:
>This is about pre-ANSI C.
>
> [Is the following legal C?]
>		(j = 2) ? k = 3 : 4;

I.e., is the assignment statement between the ? and the : legal, given
that = has lower precedence than ?:.

This issue comes up periodically.  The answer is unclear.  K & R
doesn't rightly say whether this is legal, though people have made
casuistic arguments on both sides.  I *will* note that it's
unambiguous and easily parsable, so perhaps there's no reason to
disallow it.  No doubt the pANS has resolved this one way or the other.
Meanwhile, I claim:  if you're writing a compiler, allow it; if you're
writing code, don't use it.

Jim Shankland
jas at ernie.berkeley.edu

"I've been walking in a river all my life, and now my feet are wet"



More information about the Comp.lang.c mailing list