Article View: comp.std.c
Article #4402Re: null pointer constant
From: Jerry Coffin
Date: Tue, 28 Nov 1995 18:10
Date: Tue, 28 Nov 1995 18:10
31 lines
1683 bytes
1683 bytes
becker@Xenon.Stanford.EDU (Denizen of the Deep) wrote:
>If the type (void *) is not compatible with pointer-to-function
>types, then why is the expression (void *)0 a legal null
>pointer constant?
Because 0 is compatible with any pointer type, regardless of what type
that 0 happens to be - 0, 0L, 0U, (void *)0, (char)0, (21-21), or '\0'
(which is actually no different from a bare, unadorned 0). Any integer
constant with a value of 0 is considered a special case, and is always
compatible with any pointer type, regardless of the fact that the type
given to the zero may not be in general. In fact, assigning that
integer constant to a variable of the same type may result in something
that is NOT compatible with a pointer type, whether a pointer to some
data type or a pointer to a function.
>Since the null pointer constant is assignable to a pointer-to-
>function, it seems that this is rather misleading.
Yes and no. It comes back to the simple fact that any integer constant
with a value of 0 is given special treatment - it's compatible with ANY
pointer type, regardless of the exact type of the integer constant.
Later,
Jerry.
/* I can barely express my own opinions; I certainly can't
* express anybody else's.
*
* The universe is a figment of its own imagination.
*/
Technical Details
Message-ID:
<49ffkb$g0s@natasha.rmii.com>Path:
arc1-ca.pugleaf.net!news.rmii.com!usenetReferences:
<49b202$62t@nntp.Stanford.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.rmii.com!usenet From: jcoffin@rmii.com (Jerry Coffin) Newsgroups: comp.std.c Subject: Re: null pointer constant Date: Tue, 28 Nov 1995 18:10:48 GMT Organization: TAEUS Message-ID: <49ffkb$g0s@natasha.rmii.com> References: <49b202$62t@nntp.Stanford.EDU> NNTP-Posting-Host: slip8140.rmii.com X-Newsreader: Forte Free Agent 1.0.82