Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!cmcl2!rutgers!ames!amdcad!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <24682@sun.uucp> Date: Sun, 2-Aug-87 03:13:13 EDT Article-I.D.: sun.24682 Posted: Sun Aug 2 03:13:13 1987 Date-Received: Sun, 2-Aug-87 20:12:13 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <525@murphy.UUCP> Sender: news@sun.uucp Lines: 44 > > But what does it mean to say that a pointer is "false"? Pointers > > themselves really aren't Boolean; there is a boolean predicate *on* a > > pointer, namely the "is this pointer null" predicate. > > I was hoping you were going to go in a different direction here. I > *do* like to use the constructs "if (p)" and "if (!p)"; I think that > they are quite clear in what they mean, because I do think of pointers > as being true or false: if a pointer points to something valid, then > it's a "true" pointer because you can dereference it. If it is nil, > then it's a "false" pointer because you can't dereference it. Well, you can hope for lots of things; many of them won't come true, though, so such hope is largely a waste of energy. I don't personally care for "if (p)" and "if (!p)", but I don't strongly object to them either. However, defending them by saying that you're testing whether a pointer is "true" or "false" is not valid. You can say that, for pointers, they test whether the pointer does or does not point to something valid; however, pointers are NOT Booleans. They do not have a truth value as their value. There is a boolean *predicate* on pointers, namely the "is this pointer valid" predicate. If you want to say that "if (!p)" means "if (p is not valid)", fine, but this is very different from "p is false". > Then again, it isn't something I'm religious about. Lots of people that > I respect write "if (p == NULL)" and I don't flame them for it. It's > a free country, individual choice, etc... I don't flame them either. (Anyone who disagrees with that statement has serious problems with reading comprehension; such problems are, unfortunately, quite common on USENET.) > > > Secondly it tells me that the file that the statement is in > > > includes stdio.h (or that the author of the code is a dweeb.) ... > > A legitimate gripe; you run into the same if you use TRUE and FALSE. ... If you are replying to an article that includes quotes from other articles, please try to keep the replies to the various articles separate (or, even better, make your reply to those quotes a reply to the article in which they appeared). Thank you. Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com