Example of null ptr not = 0 ?

Steve Summit scs at adam.mit.edu
Wed Nov 21 11:36:30 AEST 1990


In article <90324.143724DXB132 at psuvm.psu.edu> <DXB132 at psuvm.psu.edu>
ignores advice in the FAQ list and asks:
>Does there exist a C compiler for any "modern", commercial, 32-bit
>(or more :-)) machine (i.e. a machine like you and I use) that uses something
>other than zero (real binary zero) to mean "null pointer"? Why not just say in
>the spec "a null pointer is zero!" and be done with the whole matter?

In a futile attempt at heading off what is sure to be Yet Another
comp.lang.c null pointer rehash, I would like to ask that:

	no one follow up the referenced article,

	no one follow up this article, and

	no one follow up the inevitable followups which will
	appear before this article is distributed.

Note that the referenced article asked two questions, neither of
which ("Does there exist" and "Why not just say") should be
followed up to.

I, of course, am disobeying my own advice.  Meta-discussions are
frowned upon.  I claim some small license, as author of the FAQ,
to do so; sometimes I wonder why I bothered to write the list,
since its principal target, the neverending null pointer
discussion, seems to be flourishing quite well in spite of it.

Following my signature is a collection, from the frequently asked
questions files, of the responses that resulted the last time
someone insisted on concrete examples.  The examples are old, and
may not satisfy DXB132 at psuvm, who wants "modern, commercial, 32-bit
machines."  These examples were deliberately omitted from the
posted FAQ list, to save space; an eventual non-posted "long
form" FAQ list will include them.

I am not sure what purpose would be served by specifying that "a
null pointer is zero!", besides, of course, perhaps reducing
these interminable discussions and speculations.  (Do not follow
up to say what other purpose could be served; send mail if you
must.)

Followups to alt.religion.computers, or alt.flame.

                                            Steve Summit
                                            scs at adam.mit.edu

From: pas at uunet!unhd (Paul A. Sand)
Newsgroups: comp.lang.c
Subject: Re: What C compilers have non-zero null pointers?
Message-ID: <1990Jul10.141208.24902 at uunet!unhd>
Date: 10 Jul 90 14:12:08 GMT
References: <422 at minya.UUCP>
Reply-To: pas at unhd.UUCP (Paul A. Sand)
Organization: University of New Hampshire
Lines: 40

In article <422 at minya.UUCP> jc at minya.UUCP (John Chambers) writes:
>Anyhow, what's the story here?  Are there really C compilers that
>use something other than all-zero bits for a null pointer?  If so,
>can you name the compilers, and describe their representations and
>how they handle code like the above?

"Certain Prime computers use a value different from all-bits-0 to
encode the null pointer. Also, some large Honeywell-Bull machines use
the bit pattern 06000 to encode the null pointer. On such machines, the
assignment of 0 to a pointer yields the special bit pattern that
designates the null pointer. Similarly, (char *)0 yields the special
bit pattern that designates a null pointer."

-- "Portable C" by H. Rabinowitz and Chaim Schaap, Prentice-Hall, 1990,
page 147.  A good book. Rex Jaeschke's "Portability and the C Language"
(Hayden, 1988) makes the same point but doesn't name names.

-- 
-- Paul A. Sand
-- University of New Hampshire
-- uunet!unhd!pas -or- pas at unh.edu


From: amoore at softg.uucp
Newsgroups: comp.lang.c
Subject: Re: What C compilers have non-zero null pointers?
Message-ID: <13520 at softg.uucp>
Date: 12 Jul 90 11:37:44 GMT
References: <422 at minya.UUCP> <1990Jul10.141208.24902 at uunet!unhd>
Organization: SofTech, Waltham MA
Lines: 9

In article <1990Jul10.141208.24902 at uunet!unhd>, pas at uunet!unhd (Paul A. Sand) writes:

> "Certain Prime computers use a value different from all-bits-0 to
> encode the null pointer. 

The Prime 50 series (segmented) architecture has a segment 0.  A null
pointer on a Prime is segment 7777 location 0 (usually written 7777/0).
The C compiler (written by Garth Conboy of Pacer Software) deals with
comparisons to 0.


From: ARIEL at RELAY.Prime.COM
Newsgroups: comp.lang.c
Subject: Re: What C compilers have non-zero null
Message-ID: <108300010 at RELAY.Prime.COM>
Date: 12 Jul 90 20:17:00 GMT
References: <422 at minya.UUCP>
Lines: 21
Nf-ID: #R:minya.UUCP:-42200:RELAY:108300010:000:590
Nf-From: RELAY.Prime.COM!ARIEL    Jul 12 20:17:00 1990

A small clarification re "certain Prime computers":

The Prime 50 Series does use a non-zero representation
for NULL in some languages, particularily PL/I.

The C NULL is all 0-bits. Sometimes (in IX mode) 32 of
them, other times (V mode, on older machines) 48 bits.

If i is an int, and p is a pointer, then (in IX mode):

i = (int)p;
p = (void *)i;

changes the bit pattern. (i.e after these two statements
*(int *)&i != *(int *)&p is true if p != NULL)

The change is invertable (p ends up with the same value)
IF p is actually a valid pointer (including NULL of course)

Robert Ullmann


From: thacher at unx.sas.com (Clarke Thacher)
Newsgroups: comp.lang.c
Subject: Re: What C compilers have non-zero null pointers?
Message-ID: <1990Jul19.231038.19372 at unx.sas.com>
Date: 19 Jul 90 23:10:38 GMT
References: <422 at minya.UUCP> <1990Jul10.141208.24902 at uunet!unhd> <13520 at softg.uucp>
Organization: SAS Institute Inc.
Lines: 17

Actually the Prime 50 series has both types of pointers.
The older (PL1) style of pointer uses segment 7777 (octal) in their
NULL pointers (there can never be a segment 7777), dereferencing
this type of pointer would raise a NULL_POINTER condition.  
The newer C compiler uses a pointer with a segment of 0 and an 
offset of 0.  This pointer is still not bit equal to an integer 0
there are two extra bits (for the ring number) that may or may not
be set.  To solve this, Prime added a TCNP (test c null pointer) 
instruction to the instruction set.  They also added a bunch of other
instructions for the C compiler (mostly having to do with character
operations).

Clarke Thacher        PRIMOS Host developer          SAS Institute, Inc.
sasrer at unx.sas.com    (919) 677-8000 x7703          Box 8000, Cary, NC 27512



More information about the Comp.lang.c mailing list