Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!nap1!ark1!dtix!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr), where cptr is a * Message-ID: <18727@mimsy.UUCP> Date: 25 Jul 89 05:21:52 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> <10100@mpx2.mpx.com> <1989Jul24.194646.3012@nc386.uucp> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 30 In article <1989Jul24.194646.3012@nc386.uucp> jeffl@nc386.uucp (Jeff Leyser) writes: >OK, this may be meaningless, but out of curiosity is: > > if (cptr == (int) 0) > >illegal C, or simply compleat garbage? [where cptr was declared with `char *cptr;'] If it has a meaning, it means to compare cptr against a nil of type pointer-to-char. The question comes down to `is (int)0 an integral constant expression with value zero', because the way one writes the untyped nil pointer in C is to write an integral constant expression whose value is zero. Clearly (int)0 is an integral expression whose values is zero. Whether the cast takes away its `constant-ness' is less certain. Different compilers have had differing opinions in the past; what the current pANS says I am not sure (my copy is one or two revisions out of date, and is elsewhere at the moment anyway). The short answer is if (cptr == (int)0) is probably meaningful garbage. :-) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris