Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!web-4a.berkeley.edu!laba-4he From: laba-4he@web-4a.berkeley.edu (The Cybermat Rider) Newsgroups: comp.lang.c Subject: Re: When is a statement an expression? Message-ID: <23708@agate.BERKELEY.EDU> Date: 27 Apr 89 23:03:41 GMT References: <1043@itivax.iti.org> <1127@ptolemy.arc.nasa.gov> Sender: usenet@agate.BERKELEY.EDU Organization: University of California, Berkeley Lines: 42 In article <1127@ptolemy.arc.nasa.gov> raymond@ptolemy.arc.nasa.gov (Eric A. Raymond) writes: >In article <1043@itivax.iti.org> scs@vax3.iti.org (Steve Simmons) writes: >> a = if ( a == 1 ) >> 12 ; >> else >> 14 ; [....] >You can accomplish this behavior via the ?: connstruct: > > a = (a ? 12 : 14); ^^^^^^^^^^^^^^^^^^ Close, but not quite -- if a is 2, you'll get *12*, not 14. It should be: a = ((a == 1) ? 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. I did. Sorry, but a is guaranteed to be 3. To quote K&R 2: A7.18 Comma Operator expression: assignment-expression expression , assignment-expression A pair of expressions separated by a comma is evaluated left-to-right, and the value of the left expression is discarded. [.....] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >-- >Eric A. Raymond (raymond@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 ---------------------------------------------------------------------------- Adrian Ho a.k.a. The Cybermat Rider University of California, Berkeley laba-4he@web.berkeley.edu (WEB Evans, Home of The CS Freakies) Disclaimer: Nobody takes me seriously, so is it really necessary?