cond. op. on ='s LHS

Checkpoint Technologies ckp at grebyn.com
Thu Feb 14 09:34:12 AEST 1991


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;

Sure, I have a comment. My own opinion, of course, since both are valid
C and should produce identical results.

In nearly all cases I would use the second form. It's easier to read.
In fact I had to go over the first one twice to assure myself that it
does what the second clearly states, and clarity is a critical feature
of any program.

Note also that the first form won't necessarily work if either c or d
are register variables.

The only time I would use the first form is in a macro, in a situation
where I really wanted an expression rather than a statement.  But that's
all.
-- 
First comes the logo: C H E C K P O I N T  T E C H N O L O G I E S      / /  
                                                                    \\ / /    
Then, the disclaimer:  All expressed opinions are, indeed, opinions. \  / o
Now for the witty part:    I'm pink, therefore, I'm spam!             \/



More information about the Comp.lang.c mailing list