Topic: new bool type (unsuccessful NULL joke)


Author: gjohnson@netcom.com (Serendipitous Freelance Hacker)
Date: Fri, 4 Mar 1994 15:08:36 GMT
Raw View
In article <KANZE.94Mar3205648@slsvhdt.us-es.sel.de> kanze@us-es.sel.de (James Kanze) writes:
>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.

False sounds good to me.  I am not a fan of (void *)0, just find it funny
that something so fundamental to the language is a point of constant debate.

>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.

Yes, this is more technically correct than my attempt to poke
fun at ``not necessarily the same binary pattern as an integral 0''.
(quoting off the top of my head, my apologies if I misquoted)

>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 ) ...
>

Which is what I (and maybe I alone) find funny.  Oh well, at least I
didn't get in trouble for using ANSI instead of ISO. <- More dumb humor.

--
Gary Johnson (Freelance Hacker) gjohnson@netcom.com "Public private keys?!"