[omniORB] [omnithread] Why is NULL defined as (void*)0?

Richard Hardgrave hardgrav@ttd.teradyne.com
Thu, 23 Aug 2001 19:04:57 -0500 (CDT)


> From owner-omniorb-list@uk.research.att.com Thu Aug 23 11:56 CDT 2001
> From: "Keeley, Michael" <mkeeley@orchestream.com>
> To: "'omniorb-list@uk.research.att.com'"
	 <omniorb-list@uk.research.att.com>
> Subject: [omniORB] [omnithread] Why is NULL defined as (void*)0?
> Date: Thu, 23 Aug 2001 17:46:10 +0100
> MIME-Version: 1.0
> X-Loop: omniorb-list@uk.research.att.com
> 
> In the omnithread.h header, NULL is defined to be (void*)0.
> 
> Shouldn't this be just 0?
> Otherwise code such as
> 
> #define NULL (void*) 0
> 
> char* foo() {
>   return NULL;
> }

I believe you are a bit confused about the convention for
using NULL.  It's used in making comparisons with pointers
to objects of unknown type.  E.g.:

if ( foo() == NULL ) { ... };

(The void* gets caste to a char* for the comparison.)

No compiler will allow you to return a different "type"
than you have declared it to return.  If your function wanted
to return a long*, you would still have to caste it to
a char* before returning it.

Richard

There's altogether too much blood in my caffeine system. 8^)

> 
> will not compile - void* cannot be cast to char*.
> 
> Mike.
> 
> Michael Keeley
> ___________________________________________________________________________
> Software Engineer
> T: +44 (0)20 7348 5759
> Orchestream 
> Avon House, Kensington Village, Avonmore Road, London W14 8TS
> T: +44 (0)20 7348 1500 F: +44 (0)20 7348 1501
> www.orchestream.com
> 
> 
> 
> 
> --
> This communication contains confidential information intended solely for the use of the individual/s 
and/or entity or entities to whom it was intended to be addressed.  If you are not the intended 
recipient, be aware that any disclosure, copying, distribution, or use of the contents of this 
transmission is prohibited.  If you have received this communication in error, please contact the sender 
immediately, delete this communication from your system, and do not disclose its contents to any third 
party, or use its contents.  Any opinions expressed are solely those of the author and do not 
necessarily represent those of Orchestream Ltd or its group of companies unless otherwise specifically 
stated.
>