Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!uunet!yale!mfci!karzes From: karzes@mfci.UUCP (Tom Karzes) Newsgroups: comp.lang.c Subject: Re: A question about the tertiary (? : ) operator Message-ID: <989@m3.mfci.UUCP> Date: 23 Aug 89 21:19:46 GMT References: <612@cybaswan.UUCP> <16928@rpp386.Dallas.TX.US> Sender: karzes@mfci.UUCP Reply-To: karzes@mfci.UUCP (Tom Karzes) Organization: Multiflow Computer Inc., Branford Ct. 06405 Lines: 18 In article <16928@rpp386.Dallas.TX.US> jfh@rpp386.cactus.org (John F. Haugh II) writes: >There is a way to do this ... > > *((type_of_foobar *) flag > 0 ? &foo:&bar) = Of course there are ways to do it, the point is that the DESIRED way doesn't work. Taking the address and doing an indirect store is gross. Furthermore, what if one of foo or bar is a register variable? Using an if/else is also gross. You should simply be able to write what you want, and let the compiler generate the best code it can for it. If the expression is structure valued, then most compilers would probably want to use the above sequence. Otherwise, if the expression fits in a register, using a branch might be faster, or perhaps even using specialized hardware, if available. Or perhaps using pointers really would be better in some cases. Sure, maybe a compiler could recognize the above and eliminate the indirection when it is undesirable, but it's stupid to have to go through all of that rather than simply write what you wanted to say in the first place.