C Style (Was Re: == vs =)

George Pajari pajari at grads.cs.ubc.ca
Tue Apr 12 17:55:18 AEST 1988


In article <130 at obie.UUCP> wes at obie.UUCP (Barnacle Wes) writes:
>... `=' is NOT always invalid in an if clause:
>
>    if (status = *statreg) {

Article <5981 at utcsri.UUCP> by flaps at utcsri.UUCP (Alan J Rosenthal)
> ... better written as "if ((status = *statreg))"
> some people even recommend "if ((status = *statreg), status)"

What is wrong with:

	if ((status = *statreg) != NULL)...

Most compilers I've tried generate the same code as for the original and
this version (I claim) is the most readble (i.e. scanned quickly by a human
with the fewest resulting semantic errors) of the three.

George Pajari



More information about the Comp.lang.c mailing list