DXB132@psuvm.psu.edu (11/21/90)
I just read through the first section of the regular posting (common questions and answers) (it's about 'null pointers') and I have a down-to-earth question: 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? It just seems like a trivial academic exercise to talk about it any other way. (My humble opinion, of course :-)) Apologies if this question irritates anyone. -- Dan Babcock
barmar@think.com (Barry Margolin) (11/21/90)
In article <90324.143724DXB132@psuvm.psu.edu> <DXB132@psuvm.psu.edu> writes: >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? >It just seems like a trivial academic exercise to talk about it any other way. >(My humble opinion, of course :-)) I don't know what kind of machine you use, but I use a Symbolics Lisp Machine. This is a tagged architecture, in which the hardware and firmware directly support a number of high-level data types. In this environment, pointers are not represented numerically to begin with; they are represented using two separate Lisp objects, the first being an array or NIL, the second being a non-negative integer (the offset into the array). This representation allows attempts to reference beyond the end of an object to be detected, and allows objects to move during garbage collection. A null pointer is represented as the combination <NIL, 0>; the attempt to indirect through such a combination is trapped by the array indexing hardware (because NIL isn't an array), and signals a null pointer error. It would be possible to use <0, 0> rather than <NIL, 0> as the null pointer (since 0 isn't an array, either). However, this representation would lead one to believe that other <integer, integer> combinations are also reasonable, which would not be the case. NIL is a much better placeholder, since it doesn't carry such connotations (it's used throughout the language as a generic "empty" value). The hardest part of defining language standards is avoiding parochialism. It's not enough that C be easy to implement on the currently common machines, it should be relatively straightforward to implement it for any general purpose system. Not only would it make the language hard to implement on weird systems that currently exist, but it would also stifle experimentation with other unusual architectures. A language standard should specify all and only what programmers actually *need*; in general, high-level programmers of portable programs don't depend on the precise representation of pointers; what matters is that there is a distinguished null pointer, you can access what a non-null pointer points to. and there is a useful algebra of pointers (PL/I manages without the latter, although pointer arithmetic intrinsics were added as extensions in the Multics PL/I compiler, primarily as a convenience for systems programmers). -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar
scs@adam.mit.edu (Steve Summit) (11/21/90)
In article <90324.143724DXB132@psuvm.psu.edu> <DXB132@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@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@adam.mit.edu From: pas@uunet!unhd (Paul A. Sand) Newsgroups: comp.lang.c Subject: Re: What C compilers have non-zero null pointers? Message-ID: <1990Jul10.141208.24902@uunet!unhd> Date: 10 Jul 90 14:12:08 GMT References: <422@minya.UUCP> Reply-To: pas@unhd.UUCP (Paul A. Sand) Organization: University of New Hampshire Lines: 40 In article <422@minya.UUCP> jc@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@unh.edu From: amoore@softg.uucp Newsgroups: comp.lang.c Subject: Re: What C compilers have non-zero null pointers? Message-ID: <13520@softg.uucp> Date: 12 Jul 90 11:37:44 GMT References: <422@minya.UUCP> <1990Jul10.141208.24902@uunet!unhd> Organization: SofTech, Waltham MA Lines: 9 In article <1990Jul10.141208.24902@uunet!unhd>, pas@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@RELAY.Prime.COM Newsgroups: comp.lang.c Subject: Re: What C compilers have non-zero null Message-ID: <108300010@RELAY.Prime.COM> Date: 12 Jul 90 20:17:00 GMT References: <422@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@unx.sas.com (Clarke Thacher) Newsgroups: comp.lang.c Subject: Re: What C compilers have non-zero null pointers? Message-ID: <1990Jul19.231038.19372@unx.sas.com> Date: 19 Jul 90 23:10:38 GMT References: <422@minya.UUCP> <1990Jul10.141208.24902@uunet!unhd> <13520@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@unx.sas.com (919) 677-8000 x7703 Box 8000, Cary, NC 27512
pen@lysator.liu.se (Peter Eriksson) (11/21/90)
DXB132@psuvm.psu.edu (Dan Babcock) writes: >I just read through the first section of the regular posting (common questions >and answers) (it's about 'null pointers') and I have a down-to-earth question: >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? >It just seems like a trivial academic exercise to talk about it any other way. >(My humble opinion, of course :-)) Well... all Prime 50-series computers can use non-zero null pointers. They are 32 bit machines and not very uncommon. And there is a rather good C compiler available for them too. (They run an operating system called PRIMOS, normally). /Peter -- Peter Eriksson pen@lysator.liu.se Lysator Computer Club ...!uunet!lysator.liu.se!pen University of Linkoping, Sweden "Seize the day!"