Topic: new bool type (NULL joke)
Author: ark@tempel.research.att.com (Andrew Koenig)
Date: Wed, 2 Mar 1994 19:14:08 GMT Raw View
In article <gjohnsonCLywLL.A00@netcom.com> gjohnson@netcom.com (Serendipitous Freelance Hacker) writes:
> int i = 0;
> if( NULL == 0 && NULL != i ) LaughAtANSI();
I don't get it.
I can see no way that LaughAtANSI will ever be called in this example.
If NULL is a synonym for 0, there's no problem.
If you're one of those people who would like NULL to be implemented
as (void*)0, then the fragment will not compile, there being no
generalized conversions between int and pointer.
--
--Andrew Koenig
ark@research.att.com
Author: kanze@us-es.sel.de (James Kanze)
Date: 03 Mar 1994 19:56:48 GMT Raw View
In article <gjohnsonCLywLL.A00@netcom.com> gjohnson@netcom.com
(Serendipitous Freelance Hacker) writes:
|> In article <CJKMF1.3Co@tempel.research.att.com> ark@tempel.research.att.com (Andrew Koenig) writes:
|> >In article <2h1sm0INN67s@umbc7.umbc.edu> squire@umbc.edu (Mr. Jon S. Squire) writes:
|> >> But, but, but! You do not seem to understand that null pointers may be
|> >> non zero. This is implementation dependent, as every 'coder' should
|> >> understand.
|> >Regardless of representation, every null pointer is required to compare
|> >equal to (literal integral) zero.
|> //...
|> int i = 0;
|> if( NULL == 0 && NULL != i ) LaughAtANSI();
|> //...
As written, the above must be false. NULL is *not* a null pointer, at
least not currently. NULL is an integer constant 0, which will
implicitly convert to a null pointer constant in a pointer context.
I presume that what was meant was something like:
char* p = NULL ;
int i = 0 ;
if ( p == 0 && p != i ) ...
However, this is simply illegal. You cannot compare a pointer to an
integer, anymore than you can compare apples to oranges.
Whether you can convert a pointer to an integer is implementation
defined. (I know of implementations where pointers are 48 bits, but
the largest integer is only 32 bits.) For implementations where you
*can* do this conversion, whether the following expression is true or
false *is* undefined:
char* p = 0 ;
if ( int( p ) == 0 ) ...
--
James Kanze email: kanze@lts.sel.alcatel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
Author: gjohnson@netcom.com (Serendipitous Freelance Hacker)
Date: Tue, 1 Mar 1994 04:03:21 GMT Raw View
In article <CJKMF1.3Co@tempel.research.att.com> ark@tempel.research.att.com (Andrew Koenig) writes:
>In article <2h1sm0INN67s@umbc7.umbc.edu> squire@umbc.edu (Mr. Jon S. Squire) writes:
>
>> But, but, but! You do not seem to understand that null pointers may be
>> non zero. This is implementation dependent, as every 'coder' should
>> understand.
>
>Regardless of representation, every null pointer is required to compare
>equal to (literal integral) zero.
//...
int i = 0;
if( NULL == 0 && NULL != i ) LaughAtANSI();
//...
--
Gary Johnson (Freelance Hacker) gjohnson@netcom.com "Public private keys?!"