cond. op. on ='s LHS

Richard Harter rh at smds.UUCP
Sat Feb 16 18:21:20 AEST 1991


In article <15184 at smoke.brl.mil>, gwyn at smoke.brl.mil (Doug Gwyn) writes:
> In article <11073 at pasteur.Berkeley.EDU>, johnm at cory.Berkeley.EDU (John D. Mitchell) writes:
> - In article <4155 at cernvax.cern.ch> burow at 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) = <some complicated messy expression>

One really doesn't want to code in said messy expression twice, so one
tends to write something like

	temp = <some complicated messy expression>
	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.



More information about the Comp.lang.c mailing list