Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!linus!philabs!cmcl2!seismo!brl-tgr!tgr!roger@ll-sst From: roger@ll-sst (Roger Hale) Newsgroups: net.lang.c Subject: Re: if(p) Message-ID: <1960@brl-tgr.ARPA> Date: Mon, 7-Oct-85 17:45:21 EDT Article-I.D.: brl-tgr.1960 Posted: Mon Oct 7 17:45:21 1985 Date-Received: Wed, 9-Oct-85 06:26:41 EDT Sender: news@brl-tgr.ARPA Lines: 44 There's something I've been missing in the if(p) discussion: I see where K&R declare that comparing pointers with 0 is special (sec. 7.7), where ``condition ? pointer : 0'' is special (sec. 7.13), and where assigning 0 to pointers is special (sec. 7.14); but I don't see where if(p) invokes the same mechanism. Section 7.7 Equality operators: expression == expression expression != expression A pointer may be compared to ... the constant 0 [machine- independently]. A pointer to which 0 has been assigned ... will appear to be equal to 0[.] 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, the first substatement is executed. In the second case the second substatement is executed if the expression is 0. Section 9.4 While statement: ... remains non-zero ... Section 9.5 Do statement: ... becomes zero ... Section 9.6 For statement: ... becomes 0 ... In 9.3 ``the expression is 0'' cannot mean the constant 0, but rather that the expression evaluates to zero. There are plenty of uses of ``0'', ``zero'', and ``non-zero'' referring to what an expression evaluates to, and only three references that I've found (7.7, 7.13 and 7.14) to the special meaning of the constant 0. Initialization, section 8.6, refers to assignment's conversions and so incorporates them; but for the various conditional constructs I don't see how ``evaluates to zero'' can be taken equivalent to ``compares equal to the constant 0''. In Sum: it seems to me that ``if (p != NULL)'' is portable (NULL being 0) but ``if (p)'' is not. Please correct me if I be wrong, before I mislead countless others. Roger Hale