Path: utzoo!attcan!uunet!steinmetz!davidsen
From: davidsen@steinmetz.ge.com (William E. Davidsen Jr)
Newsgroups: comp.lang.c
Subject: Re: pointers, tests, casts
Message-ID: <12690@steinmetz.ge.com>
Date: 29 Nov 88 15:47:39 GMT
References: <11130@dartvax.Dartmouth.EDU> <8961@smoke.BRL.MIL>
Reply-To: davidsen@crdos1.UUCP (bill davidsen)
Organization: General Electric CRD, Schenectady, NY
Lines: 22

In article <8961@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes:
| In article <11130@dartvax.Dartmouth.EDU> Eric.J.Bivona@Dartmouth.EDU writes:
| >I have a question about tests on pointers, ...
| 
| 	if ( !ptr )
| and
| 	if ( ptr == 0 )
| are both perfectly valid ways to test for a null pointer.  You can
| explicitly cast the 0 to the proper type, but it's not necessary.

Doug, as usual you are correct, but I have to point out that
	if (ptr == NULL)
also works, usually generates the same code, and gives a much better
idea of what the code is doing. I'm sure that some of the new readers of
this group would not quickly grasp the meaning of your first example,
and I'm not sure about the second. I just covered this topic in a C
course I'm teaching, and I am always amazed at how easily new C
programmers are confused by shorthand form which "mean the same thing."
-- 
	bill davidsen		(wedu@ge-crd.arpa)
  {uunet | philabs}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me