comma operator
Blair P. Houghton
bph at buengc.BU.EDU
Sat Aug 5 03:34:14 AEST 1989
In article <2135 at zaphod.axion.bt.co.uk> skilbane at zaphod.axion.bt.co.uk writes:
>From article <2963 at solo6.cs.vu.nl>, by roemer at cs.vu.nl (Roemer Lievaart):
>> tada at athena.mit.edu (Michael Zehr) writes:
>
>Personally, I think it is worse that {;}. If you have something of the form
>
> x = Expr1 , Expr2;
>
>then Expr2 will be assigned to x, rather than Expr1. If you rewrite them as
No. For precedence, the comma operator is the lowest of the low.
Checking the table on p. 18 of Andrew Koenig's _C_Traps_and_Pitfalls_
(I'd have looked in K&RI, but Andy's book was closer).
One sees that the bottom three, in decreasing order, are
?:
assignments
,
so in the example above, x would be assigned Expr1, and the statement
would "return" the value of Expr2, esentially returning it nowhere,
the implications of which are moot, and were discussed here sometime
around January. E.g.,
x = a ? b : c , a ? c : b ;
As far as x is concerned, this reads as
if ( a != 0 )
x = b;
else
x = c;
--Blair
" what ? me : worry ; "
More information about the Comp.lang.c
mailing list