🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #784

Re: NULL = ((void *)0) problem

#784
From: Fergus Henderson
Date: Sat, 07 Oct 1995 13:04
42 lines
1953 bytes
jaf3@motel6.cec.wustl.edu (Stephen W. Gevers) writes:

>Andy J Robb <AJRobb@pavilion.co.uk> wrote:
>:Ron Forrester <rjf@infograph.com> wrote:
>:...
>:>Of course, upon further examination we found that g++ is complaining
>:>because NULL is defined as ((void *)0). Defining NULL as (0) makes the
>:>warning go away.
[...]
>:It is madness if ANSI C++ allows implict casting of an integral value
>:of a different size (zero) to a pointer but NOT ((void*)0).
>
>The reason that you cannot implicitly cast (void*) 0 to a null pointer
>is because it would be a type hole (one that C currently allows):

If that is the reason, then it is a bogus reason.
Allowing `(void *)0' to be implicitly converted to a null
pointer does not create any type holes.

>#define	NULL ((void *) 0)
>
>char	*ptr = NULL;	// means char *ptr = ((void *) 0);

There is no type hole here.
The code simply assigns a null pointer to `ptr'.
What's the problem?

>what makes this different from
>
>long	l;
>void	*x = &l;
>char	*p = x;

The difference is that a null pointer can be safely converted
to any type, whereas that property doesn't hold of pointers in
general.

-- 
Fergus Henderson             |  "Australia is the richest country in the world,
fjh@cs.mu.oz.au              |   according to a new system of measuring wealth
http://www.cs.mu.oz.au/~fjh  |   announced by the World Bank yesterday."
PGP: finger fjh@128.250.37.3 |  - Melbourne newspaper "The Age", 18 Sept 1995.
Technical Details
Message-ID: <9528023.17178@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!munta.cs.mu.OZ.AU!fjh
References: <435jf3$1iq@globe.indirect.com> <44vqv4$ael@s02.pavilion.co.uk> <4546nd$nnl@oldfart.ecl.wustl.edu>

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.help,comp.lang.c++
Path: arc1-ca.pugleaf.net!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: NULL = ((void *)0) problem
Message-ID: <9528023.17178@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <435jf3$1iq@globe.indirect.com> <44vqv4$ael@s02.pavilion.co.uk> <4546nd$nnl@oldfart.ecl.wustl.edu>
Date: Sat, 7 Oct 1995 13:04:56 GMT