Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!ames!haven!uvaarpa!mcnc!decvax!shlump.nac.dec.com!tkou02.enet.dec.com!diamond From: diamond@tkou02.enet.dec.com (diamond@tkovoa) Newsgroups: comp.lang.c Subject: Re: Is "if (!pointer)" as portable as "if (pointer == NULL)" ??? Keywords: portability, pointers, NULL Message-ID: <1461@tkou02.enet.dec.com> Date: 11 Apr 90 05:06:18 GMT References: <656@hades.OZ> Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 20 In article <656@hades.OZ> greyham@hades.OZ (Greyham Stoney) writes: > if ((buffer = malloc(50)) != NULL) >But can you also just do an aritmetic check on the cast value of the pointer?: > if (buffer = malloc(50)) /* yes, that SHOULD be =, not == */ Yes it is portable, just not readable. They both have the same effect, and should generate identical code. But you notice that the second one is longer, because you have to include that comment in order to make it almost as readable as the first one. > if (buffer) free(buffer) This is also portable, and almost readable. Again, to be really readable, you should still compare to NULL, but I grant that it would make your source code longer this time. -- Norman Diamond, Nihon DEC diamond@tkou02.enet.dec.com This_blank_intentionally_left_underlined________________________________________