Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!emory!gatech!mcnc!rti!sheol!throopw From: throopw@sheol.UUCP (Wayne Throop) Newsgroups: comp.lang.c Subject: Re: cond. op. on ='s LHS Summary: "sump'n amis here... I'll run through it... 'Ho, ha, guard...'" Message-ID: <1210@sheol.UUCP> Date: 18 Feb 91 02:51:51 GMT References: <11073@pasteur.Berkeley.EDU> <15184@smoke.brl.mil> <326@smds.UUCP> <1196@sheol.UUCP> <331@smds.UUCP> Lines: 52 > rh@smds.UUCP (Richard Harter) [.. discussing assignment to expressions like *(a==b?&c:&d) ..] > First of all the trick of using > *(cond?&var1:&var2) is not technically legal since the result of the > ?: is not an lvalue. [Harbison & Steele]. I rather suspect you could > sneak it past most compilers though. Well... I'd say "all correct C compilers" really ought to be "most", wouldn't you? As Dan Bernstein has pointed out in another article, Richard is incorrect here. While it is true that the result of ?: is never an lvalue, this is irrelevant since the result of * always is. > Secondly the syntax of the condition is, in its own right, ugly. No uglier than much else of C's alphabet soup operators, I'd say. > Thirdly, the use of the conditional in an lvalue obscures the destination > of an assignment. I agree, but this is appropriate if the destination is, in fact, obscure or arcane. That is, I agree it is something to be avoided, but I think it may sometimes be the least of the available evils. > Fourthly, the ?: is hard to read (see second complaint above). Again, I agree with the same reservation as in "thirdly" above. > Fifthly, the original example is an instance of making code less efficient > in the process of reducing the number of statements since you have to > reference and dereference. It's a pretty poor compiler that would be confused by this into doing something noticeably inefficent. On the other hand, I think it is Morally Wrong to invoke extraneous operations. (And even if I'm a little vague on what can be classed as extraneous, I would be perverse not to include the address-of operation in the example under discussion as extraneous.) Keep in mind: I agree that ?: is not well suited for the LHS of expressions... I was just overreacting to what I perceived as an oversimple blanket condemnation. (Before chastizing me on grounds that this is all in my mind, realize that I KNOW that... but taking what has been said as a blanket condemnation is an error worth warning folks against, isn't it? Well... isn't it?) -- Wayne Throop !mcnc!rti!sheol!throopw or sheol!throopw@rti.rti.org