Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uflorida!haven!ncifcrf!nlm-mcs!adm!smoke!gwyn
From: gwyn@smoke.BRL.MIL (Doug Gwyn )
Newsgroups: comp.lang.c
Subject: Re: pointers, tests, casts
Message-ID: <9014@smoke.BRL.MIL>
Date: 30 Nov 88 16:47:20 GMT
References: <11130@dartvax.Dartmouth.EDU> <8961@smoke.BRL.MIL> <12690@steinmetz.ge.com>
Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) )
Organization: Ballistic Research Lab (BRL), APG, MD.
Lines: 22

In article <12690@steinmetz.ge.com> davidsen@crdos1.UUCP (bill davidsen) writes:
-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."

I wasn't recommending anything other than if(ptr==NULL) (which requires
that the programmer arrange for NULL to be properly defined first, but
I always do arrange that for my code).  In fact I wasn't making any
stylistic suggestion at all, just answering a specific question.