Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!nstn.ns.ca!news.cs.indiana.edu!samsung!usc!apple!netcom!teda!ditka!mcdchg!tellab5!balr!clrcom!rmartin From: rmartin@clear.com (Bob Martin) Newsgroups: comp.lang.c Subject: Re: cond. op. on ='s LHS Message-ID: <1991Feb14.230403.9754@clear.com> Date: 14 Feb 91 23:04:03 GMT References: <4155@cernvax.cern.ch> Organization: Clear Communications, Inc. Lines: 38 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; > >thanks, burkhard burow%13313.hepnet@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@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. |