Path: utzoo!attcan!uunet!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Is "if (!pointer)" as portable as "if (pointer == NULL)" ??? Keywords: portability, pointers, NULL Message-ID: <16437@haddock.ima.isc.com> Date: 11 Apr 90 16:40:29 GMT References: <656@hades.OZ> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 19 In article <656@hades.OZ> greyham@hades.OZ (Greyham Stoney) writes: >But can you also just do an aritmetic check on the cast value of the pointer?: No. >K&R says that casting anything with a value 0 to a pointer yeilds a NULL >pointer; so presumably casting a NULL pointer back to value yeilds a zero. Not necessarily. > if (buffer = malloc(50)) /* yes, that SHOULD be =, not == */ > if (buffer) free(buffer) But these are acceptable (if you like that style, which I don't). You seem to believe that `if (buffer)' means `if ((int)buffer != 0)' (which would not be a valid test), but in fact it means `if (buffer != (char *)0)' (which is quite correct). Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint