Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!lll-lcc!lll-tis!ames!oliveb!sun!gorodish!guy
From: guy%gorodish@Sun.COM (Guy Harris)
Newsgroups: comp.lang.c
Subject: Re: What is NULL?  There is no right answer!
Message-ID: <23490@sun.uucp>
Date: Wed, 15-Jul-87 05:01:22 EDT
Article-I.D.: sun.23490
Posted: Wed Jul 15 05:01:22 1987
Date-Received: Fri, 17-Jul-87 04:36:44 EDT
References: <1810@megaron.arizona.edu> <23368@sun.uucp> <800@unc.cs.unc.edu>
Sender: news@sun.uucp
Lines: 29
Keywords: NULL 0 pointer C

> Is there any guarantee that coercing (type1 *)0 into a (type2 *) yields
> (type2 *)0 ?

No.

> In particular, might
> 	if (foo == 0)
> differ from
> 	if (foo == (char *)0)
> in some implementation of ANSI C where (char *) and (void *) have
> different representations?

Well, if "foo" is of type "char *", the two are obviously the same.
If "foo" is not of type "char *", the first is a comparison of it
with a null pointers, while the second does not have a well-defined
meaning.  The only pointer conversions that are described in 3.2.2.3
"Pointers" are conversions of pointers to or from type "pointer to
void", and conversions of integral constant expressions with the
value 0 to pointer types.

I wouldn't count on the latter construct doing what you expect, or
even count on it being permitted by the compiler, if "char *" and the
type of "foo" had different representations (which could happen even
if "char *" and "void *" have different representations - "void *"
does not appear in your example, and its representation isn't
relevant).
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com