time(0L) - history of a misconception (was Re: SCO password generator)

Steve Summit scs at adam.mit.edu
Sat May 25 10:57:39 AEST 1991


In article <1991May24.151350.22705 at holos0.uucp> lbr at holos0.uucp (Len Reed) writes:
>Under what architecture is a NULL pointer not "all bits 0"?
>...
>(Maybe there's
>a loophole here in ANSI that says that (void *)0 is a null pointer but
>the compiler could implement that casted zero as somthing other than
>a pattern of zeros.  Not likely in the real world.)

It's not at all unlikely.

For those of you who have no access to or interest in comp.lang.c,
here are two relevant answers from its frequently-asked questions list:

13.  Given all the confusion surrounding null pointers, wouldn't it be
     easier simply to require them to be represented internally by
     zeroes?

A:   If for no other reason, doing so would be ill-advised because it
     would unnecessarily constrain implementations which would otherwise
     naturally represent null pointers by special, nonzero bit patterns,
     particularly when those values would trigger automatic hardware
     traps for invalid accesses.

     Besides, what would this requirement really accomplish?  Proper
     understanding of null pointers does not require knowledge of the
     internal representation, whether zero or nonzero.  Assuming that
     null pointers are internally zero does not make any code easier to
     write (except for a certain ill-advised usage of calloc; see
     question 52).  Known-zero internal pointers would not obviate casts
     in function calls, because the _size_ of the pointer might still be
     different from that of an int.

14.  Seriously, have any actual machines really used nonzero null
     pointers?

A:    "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."

                 -- Portable C, by H. Rabinowitz and Chaim Schaap,
                 Prentice-Hall, 1990, page 147.

     The "certain Prime computers" were the segmented 50 series, which
     used segment 07777, offset 0 for the null pointer, at least for
     PL/I.  Later models used segment 0, offset 0 for null pointers in
     C, necessitating new instructions such as TCNP (Test C Null
     Pointer), evidently as a sop to all the extant poorly-written C
     code which made incorrect assumptions.

     The Symbolics Lisp Machine, a tagged architecture, does not even
     have conventional numeric pointers; it uses the pair <NIL, 0>
     (basically a nonexistent <object, offset> handle) as a C null
     pointer.

                                            Steve Summit
                                            scs at adam.mit.edu



More information about the Comp.unix.sysv386 mailing list