[comp.os.minix] NULL macro

cwr@pnet01.cts.com (Will Rose) (11/15/89)

Rex Jaesche, who was (is?) a member of the ANSI C standards committe,
discussed this macro extensively in the Sep/Oct 88 C Users Journal.  His
summary was that ANSI C (in which we *believe*, right?) had three possible
definitions for the NULL pointer constant:

     #define NULL 0
     #define NULL 0L
     #define NULL (void *)0

Most MSDOS C compilers (he goes on to say) conditionally compile NULL into one
of the first two definitions; the third case should work in all
ANSI-conforming programs, but there are plenty of cases where it won't work in
non-ANSI code.

To understand why, read his (six page) article.

Will
-----------------------------------------------------------------------
"If heaven too had passions  | Will Rose
     even heaven would       | UUCP: {nosc ucsd hplabs!hp-sdd}!crash!pnet01!cw
     grow old."  -  Li Ho.   | ARPA: crash!pnet01!cwr@nosc.mil
                             | INET: cwr@pnet01.cts.com


UUCP: {nosc ucsd hplabs!hp-sdd}!crash!pnet01!cwr
ARPA: crash!pnet01!cwr@nosc.mil
INET: cwr@pnet01.cts.com

henry@utzoo.uucp (Henry Spencer) (11/16/89)

In article <710@crash.cts.com> cwr@pnet01.cts.com (Will Rose) writes:
>     #define NULL 0
>     #define NULL 0L
>     #define NULL (void *)0
>
>Most MSDOS C compilers (he goes on to say) conditionally compile NULL into one
>of the first two definitions; the third case should work in all
>ANSI-conforming programs, but there are plenty of cases where it won't work in
>non-ANSI code.

Actually, all three definitions *will* work in all ANSI-conforming programs
compiled on ANSI-conforming implementations.  The choice between them is
based solely on the desire to break as few non-conforming programs as
possible, by making NULL be a zero of the "right size" (the "void *" choice
is there because some machines have pointers longer than "long").  Of course,
on some machines there *is* no single "right size", or a zero is not the
right bit pattern, in which case non-conforming programs are up the creek.