🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #11737

Re: Ultimate Wait-GetMsg strategy (?)

#11737
From: Patrick R. Michaud
Date: Thu, 09 Mar 1989 04:07
54 lines
3231 bytes
In article <6445@dayton.UUCP> joe@dayton.UUCP (Joseph P. Larson) writes:
>>In article <331@wn2.sci.kun.nl> janhen@wn2.sci.kun.nl (Jan Hendrikx) writes:
>>|(!expr) means the same as (expr != 0), which is THE test to test for a 
>>|NULL pointer. Even if NULL pointers are internally not represented by
>>|all-bits-zero, the compiler must recognize a comparison between a
>>|pointer and the constant 0, and emit approprate code in case that that
>>|compiler's internal representation of a NULL pointer is not the same
>>|as 0.

Absolutely.

>Irregardless of whether this works or not, it is better style to compare
>against NULL, a value that indicates a pointer to nowhere.

This is, of course, simply a matter of style.

>What if address zero is a legal address?  

In 'C', zero is _never_ a legal address. Refer to section 5.4 (page 97
in my book) of "The C Programming Language" by Kernighan and Ritchie:

   "C guarantees that no pointer that validly points at data will
   contain zero, so a return value of zero can be used to signify 
   an abnormal event.... We write NULL instead of zero, however, 
   to indicate more clearly that this is a special value for a 
   pointer."

>NULL might be -1 then.  You don't
>know how some odd machine is going to work in the future.
>So THE test for comparing a pointer against NULL is to compare it against
>NULL, not to depend on what NULL's value might be.  !expr or expr == 0
>works, but that is simply because on most machines, NULL is going to be
>zero.

Again, see above. If C is properly implemented, then the value of NULL 
almost has to be zero; or, at the very least, the compiler MUST be able
to properly test pointer comparisons against zero.

Personally, I really do prefer !expr over expr==0; it seems to say
"if expr is not a valid pointer, then..." But again, this is probably 
only a matter of personal taste.

>-- 
>          When you fall on your head do you land on your feet?
>UUCP: rutgers!dayton!joe   (Feed my      Dayton Hudson Department Store Company
>ATT : (612) 375-3537       picture       Joe Larson/MIS 1060
>(standard disclaimer...)   collection)   700 on the Mall      Mpls, Mn. 55402

////////////////////////////////////////////////////////////////////////
// Patrick R. Michaud			UUCP: ...!uunet!dalsqnt!usl!prm
// USL/NASA Project Leader		      ...!cs.utexas.edu!usl!prm
// Univ. of Southwestern Louisiana	INET: prm@usl.usl.edu
//     - "Programmer at Large"
////////////////////////////////////////////////////////////////////////
Technical Details
Message-ID: <711@usl.usl.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!apple!rutgers!bellcore!texbell!killer!pollux!dalsqnt!usl!prm
References: <8902100658.AA16049@postgres.Berkeley.EDU> <6777@polya.Stanford.EDU> <6402@dayton.UUCP> <331@wn2.sci.kun.nl> <562@ivucsb.UUCP> <6445@dayton.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!apple!rutgers!bellcore!texbell!killer!pollux!dalsqnt!usl!prm
From: prm@usl.usl.edu (Patrick R. Michaud)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Ultimate Wait-GetMsg strategy (?)
Summary: NULL should always be zero
Keywords: NULL == 0
Message-ID: <711@usl.usl.edu>
Date: 9 Mar 89 04:07:01 GMT
References: <8902100658.AA16049@postgres.Berkeley.EDU> <6777@polya.Stanford.EDU> <6402@dayton.UUCP> <331@wn2.sci.kun.nl> <562@ivucsb.UUCP> <6445@dayton.UUCP>
Reply-To: prm@usl.usl.edu (Patrick R. Michaud)
Organization: CACS, Univ of SW La, Lafayette, LA
Lines: 54