Assignments in conditionals

geacc022%timevx at CIT-HAMLET.ARPA geacc022%timevx at CIT-HAMLET.ARPA
Tue Jul 16 01:12:48 AEST 1985


    There  is  one  place where the "if ((fp = fopen()) == NULL)"
syntax	is  very  useful, and that is in a series of "else if"'s.
If  you  can  keep  your else if's lined up, the code looks a lot
neater (and is generally easier to read).  to wit:

    if (something) {
	...
    }
    else if ((fp = fopen()) == NULL) {
	...
    }
    else if ((fp2 = fopen()) == NULL) {
	...
    }

    Try  writing  the  equivalent  code  without  assignments  in
conditionals,  and you'll see what I mean.  Once you have written
a  few	programs like this, this form becomes at least as easy to
read as two separated statements.

			    Gary Ansok
			    geacc022%timevx @ cit-hamlet.arpa
				(for the moment, anyway)



More information about the Comp.lang.c mailing list