When do you use "if ( a = b )"? (was Re: Funny mistake)

Josef Wolf Sepp at ppcger.ppc.sub.org
Thu Mar 21 08:40:33 AEST 1991


torek at elf.ee.lbl.gov (Chris Torek) writes:
] Smaller source code, yes.  Smaller or faster object code---well, if
] your compiler generates different code for

] 	if (a = b)

] than for

] 	a = b;
] 	if (a)

] then your compiler is not worth what you paid for it.

You might be right in this point of view, but...

Do you want the compiler to do your work? Do you think your employer
would be happy? (ok, just joking ;-)

Now let me comment your code:
The upper code tends to be more clearly (_my_ opinion). If you got into
that trap once or twice, you won't ever forget this problem. I've done this
error _one_ time (well, we're not at the end of time ;-). It took about
a week to find the bug. But now I'm pretty sure, I've never done _THAT_
sort of bug since these times... And now I like this sort of assignments
because they are
a.) short
b.) clear (there are no unnecessary types around it to confuse you)

The other problem is: if you change the name of expression 'a', you need
to make some more changes -> you will get more chances to produce _new_
bugs.

Well, the above is _my_ opinion. You have to find _your_ way to get
around this problem.

Greetings

    Sepp

PS: I also got trapped into the
        foo (bar (a1, ..., aN), aN+1);
    versus
        foo (bar (a1, ..., aN, aN+1));
    problem. And I'm pretty sure, I won't get into _that_ trap next
    years :-)

| Josef Wolf, Germersheim, Germany | +49 7274 8047  -24 Hours- (call me :-)
| ...!ira.uka.de!smurf!ppcger!sepp | +49 7274 8048  -24 Hours-
|     sepp at ppcger.ppc.sub.org      | +49 7274 8967  18:00-8:00, Sa + Su 24h
|  "is there anybody out there?"   | all lines 300/1200/2400 bps 8n1



More information about the Comp.lang.c mailing list