When do you use "if ( a = b )"? (was Re: Funny mistake)
Erik Bergersjo
d9erikb at dtek.chalmers.se
Fri Mar 22 07:30:27 AEST 1991
In article <65837 at eerie.acsu.Buffalo.EDU> chu at acsu.buffalo.edu (john c chu)
writes:
>[concerning "if ( a = b )"
>
>Is there a good use for this?
There sure is. I can think of two major uses:
(I) b is a function, perhaps returning a pointer to something
on success and NULL otherwise.
(II) b is a hardware register, cleared on reading.
Of course, in both cases "a = b; if( a )..." would do, but if you don't
have a good optimizing compiler the final code might get worse.
Besides, I think "if(a = b)" is more readable. It's clearly one of those
extra features / pecularities that make C the special language it is!
===============================================================================
Chalmers University | . . | "A message worth
of Technology | Real life: Erik Bergersj o | spreading is
Sweden | E-mail: d9erikb at dtek.chalmers.se | worth reading"
===============================================================================
More information about the Comp.lang.c
mailing list