Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: $Revision: 1.6.2.16 $; site ISM780.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!think!ISM780!marv From: marv@ISM780.UUCP Newsgroups: net.lang.c Subject: Re: RE: if(p) Message-ID: <30000017@ISM780.UUCP> Date: Tue, 8-Oct-85 15:54:00 EDT Article-I.D.: ISM780.30000017 Posted: Tue Oct 8 15:54:00 1985 Date-Received: Sat, 12-Oct-85 05:37:22 EDT References: <1671@brl-tgr.UUCP> Lines: 50 Nf-ID: #R:brl-tgr:-167100:ISM780:30000017:000:2336 Nf-From: ISM780!marv Oct 8 15:54:00 1985 >/* Written 7:21 pm Oct 7, 1985 by gwyn@brl-tgr in ISM780:net.lang.c */ >> 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". Just to add more flames to this theological discussion, from my reading of section 9.3, I draw the inference that if p is a pointer then: if(p) statement is not a valid construct in the C language and therefore questions of portability are rendered moot. My reasoning is as follows. The phrase, "In both cases the expression is evaluated and if it is non-zero" does not imply comparison to zero. Instead it implies that the expression must be of a numeric type since only numeric data have the property of 'zeroness'. The expression consting only of a pointer variable evaluates either to a pointer to some object or to a pointer to no object. It does not evaluate to zero or not zero. On the other hand, the expression p==0 is an expression of type int. In fact it evaluates to the integer 0 or 1 (K&R section 7.6 Relational operators). Parenthetically, the symbol '0' is overloaded in the C language. In the context of a pointer it *represents* the constant that points to no object. in the context of a number it *represents* the constant with the value zero. i.e., the symbol '0' is not the value of either of the the constants, it is mearly the *name* used to identify either of the constants in the *source* from of a program. I also suggest that if we take the stance that "evaluates to zero" implies comparison to zero we could also claim that: i = 0; if (p == i) is equivalent to: if (p == 0) and I believe that most C theologians would reject the above equivalence. The fact the K&R is very fuzzy about the type of an expression (as opposed to the types of primitive operands) leads to many a theological discussion. George Bool sure simplified my life, Marv Rubinstein -- Interactive Systems