Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!ima!dirtydog!karl From: karl@ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: cond. op. on ='s LHS Message-ID: <1991Feb14.041559.27478@dirtydog.ima.isc.com> Date: 14 Feb 91 04:15:59 GMT References: <4155@cernvax.cern.ch> Sender: news@dirtydog.ima.isc.com (NEWS ADMIN) Reply-To: karl@ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 22 In article <4155@cernvax.cern.ch> burow@cernvax.cern.ch (burkhard burow) writes: > *(a==b?&c:&d) = 1; What you really want is (a==b?c:d) = 1; which should (IMHO) be legal (i.e. the result of ?: is an lvalue if both subexpressions are lvalues), but this isn't the case in Standard C. (But GCC supports it as a non-standard extension.) So far everyone has complained about using ?: instead of the "clearer" method of putting the assignment inside the conditional. Nobody has mentioned yet that the above form does have one advantage, which becomes more obvious when the RHS is a complicated expression: you can write it just once without using a temporary. If the GCC extension were standard, I'd use it in such a case (just as I use x=(a==b?c:d) in real C when appropriate). But since it isn't, and making it legal by adding the extra *...&...& is a lose, I'd probably declare a temp variable and use (a==b?c=T:d=T) instead. (Or the equivalent if-else form, if it's in a statement context.) Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint