When is a statement an expression?
Eric A. Raymond
raymond at ptolemy.arc.nasa.gov
Thu Apr 27 17:58:15 AEST 1989
In article <1043 at itivax.iti.org> scs at vax3.iti.org (Steve Simmons) writes:
>
> a = if ( a == 1 )
> 12 ;
> else
> 14 ;
Sorry, but C is not LISP. That is, compund (or complex) statements do
not return values.
You can accomplish this behavior via the ?: connstruct:
a = (a ? 12 : 14);
Incidently, I beleive the comma operator allows you to approach a
progn (or is it prog1?):
a = (x=1, y=2, z=3);
A is 3 if the last expr is returned (progn-like), otherwise 1
(prog1-like). Look it up.
--
Eric A. Raymond (raymond at ptolemy.arc.nasa.gov)
G7 C7 G7 G#7 G7 G+13 C7 GM7 Am7 Bm7 Bd7 Am7 C7 Do13 G7 C7 G7 D+13: Elmore James
More information about the Comp.lang.c
mailing list