cond. op. on ='s LHS
Bob Martin
rmartin at clear.com
Fri Feb 15 10:04:03 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;
>
>thanks, burkhard burow%13313.hepnet at csa3.lbl.gov
Burkhard:
There are a number of disadvantages to the first case above. I will discuss
the least important ones first.
1. It probably generates more code. The pointer operations will force the
poor compiler to generate pointer references and dereferences.
2. It wont work if c or d happen to be register variables.
3. It wont work if c and d are of different types. (i.e. int c; double d;)
4. It is cryptic.
In general it is not true that code gets better if you remove whitespace, or
use clever little tricks. With a few notable exceptions, the most important
feature of code (other than that it should work) is that it should be
easy to read and understand. Unless you are horribly pressed for execution
speed or memory space, you should be willing to make concessions to these
goals for the goal of readability.
--
+-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for |
| rmartin at clear.com |:R::R:C::::M:M:M:M:| my words but me. I want |
| uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all |
+----------------------+:R::R::CCC:M:::::M:| the blame. So there. |
More information about the Comp.lang.c
mailing list