Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site ssc-vax.UUCP Path: utzoo!linus!decvax!bellcore!petrus!sabre!zeta!epsilon!gamma!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!ssc-vax!savage From: savage@ssc-vax.UUCP (Lowell Savage) Newsgroups: net.lang.c Subject: Re: if(p) Message-ID: <269@ssc-vax.UUCP> Date: Tue, 8-Oct-85 13:25:14 EDT Article-I.D.: ssc-vax.269 Posted: Tue Oct 8 13:25:14 1985 Date-Received: Fri, 11-Oct-85 07:01:26 EDT References: <1671@brl-tgr.ARPA> <516@talcott.UUCP> <2245@ukma.UUCP> Organization: Boeing Aerospace Co., Seattle, WA Lines: 35 In article <1671@brl-tgr.ARPA> ukma!david@ANL-MCS.ARPA (David Herron) writes: > In article <516@talcott.UUCP> tmb@talcott.UUCP (Thomas M. Breuel) quotes: > >In article <1671@brl-tgr.ARPA>, ART@ACC.ARPA (Art Berggreen) writes: > >> From an abstract language viewpoint, an "if" statement conditionally > >> executes a block of statements based on whether the control statement > >> evaluates to a condition of *TRUE*. Pointers by themself do not > >> have attributes of TRUE vs FALSE. Thus, "if(pointer)" makes less semantic > > I disagree... Pointers have VALID and INVALID values. So when you > say if(p) you're asking if it has a VALID or INVALID value. It's > just that conveniently most machines have 0 as the INVALID value. No, C *GUARANTEES* that 0 is an invalid pointer value. Page 192 of my copy of K&R (this is the end of section 7.14 of appendix A) says: "... However, it is guaranteed that assignment of the constant 0 to a pointer will produce a null pointer dis- tinguishable from a pointer to any object." And page 97 (the middle of section 5.4 Address Arithmetic) says: "C guarantees that no pointer that validly points at data will contain zero, so a return value of zero can be used to signal an abnormal event, ...." So I agree with David, except that this is not a machine-dependant thing, it is defined into the C language!! If the machine doesn't support it directly, the compiler must generate whatever code it needs to support "zero pointer = invalid pointer". So in other words, the compiler has builtin support for "VALID-pointer = TRUE" and "INVALID-pointer = FALSE", and I find this concept very useful and helpful--as well as quicker. There's more than one way to be savage, Lowell Savage