if(p)

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Tue Oct 8 09:21:18 AEST 1985


>     Section 9.3 Conditional statement:
> 	if ( expression ) statement
> 	if ( expression ) statement else statement
>     In both cases the expression is evaluated and if it is non-zero,
                                                    ^^^^^^^^^^^^^^^^^
This implies a comparison against 0.  Therefore if "expression" is a
pointer, this is comparison of a pointer with 0, which is the special
case previously discussed.  There is no concept of "evaluates to zero"
independently of "comparison with zero".

>     the first substatement is executed.  In the second case the second
>     substatement is executed if the expression is 0.

Don't take K&R too much as gospel.  It is an excellent book,
but it really did not try to specify everything to the level
that a language lawyer would want.  (X3J11 is trying to do that.)
K&R has to be read with the attitude of extracting the "spirit"
of the language from what is implied as well as from what is said.



More information about the Comp.lang.c mailing list