Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!bu.edu!m2c!jjmhome!smds!rh From: rh@smds.UUCP (Richard Harter) Newsgroups: comp.lang.c Subject: Re: cond. op. on ='s LHS Summary: Ugly can sometimes be useful Message-ID: <326@smds.UUCP> Date: 16 Feb 91 07:21:20 GMT References: <4155@cernvax.cern.ch> <11073@pasteur.Berkeley.EDU> <15184@smoke.brl.mil> Organization: SMDS Inc., Concord, MA Lines: 44 In article <15184@smoke.brl.mil>, gwyn@smoke.brl.mil (Doug Gwyn) writes: > In article <11073@pasteur.Berkeley.EDU>, johnm@cory.Berkeley.EDU (John D. Mitchell) writes: > - In article <4155@cernvax.cern.ch> burow@cernvax.cern.ch (burkhard burow) writes: > - >I'm wondering if anyone has any comments on using: > - > *(a==b?&c:&d) = 1; > - >instead of: > - > if (a==b) c=1; > - > else d=1; > My comment was going to be that it sucked bigtime. However, I'll > buy "ugh" as a suitable comment too. > - P.S. No wonder people complain about the denseness of C code! > C code has nothing to do with it, more like the density of some coders. But Doug, isn't it one of the unwritten rules of C coding that the number of special characters be greater than the number of alphanumeric characters? :-) Seriously, there is a germ of a good idea here. The example is inane, but consider *(a==b?&c:&d) = One really doesn't want to code in said messy expression twice, so one tends to write something like temp = if (a==b) c = temp; else d = temp; Again this is more readable (and mainatainable). However the ugly one liner is better code in the sense of not having replications of a single term or in using temporaries. To be honest this is a trick I would have never thought of and would never use in C. In principle the idea is a good one but the C conditional expression is just too darned ugly. -- Richard Harter, Software Maintenance and Development Systems, Inc. Net address: jjmhome!smds!rh Phone: 508-369-7398 US Mail: SMDS Inc., PO Box 555, Concord MA 01742 This sentence no verb. This sentence short. This signature done.