[TUHS] reviving a bit of WWB

John Cowan cowan at ccil.org
Mon Sep 21 12:24:17 AEST 2020


ISO requires that NULL be defined in locale.h, stddef.h, stdio.h, stdlib.h,
string.h, time.h, wchar.h, and their C++ equivalents clocale etc..  It's
pretty unlikely that you can write any useful code at all without NULL
being defined as a side effect.

On Sun, Sep 20, 2020 at 8:01 PM Clem Cole <clemc at ccc.com> wrote:

> I was also stating (under Henry’s 10th) using a properly defined macro
> with the complete cast scheme will be correct and portable to all known
> conforming C compilers no matter the target HW architecture — which in a
> commercial SW setting is highly valued.
>
> Clem
>
> On Sun, Sep 20, 2020 at 7:53 PM Clem Cole <clemc at ccc.com> wrote:
>
>> Norman NULL has to be defined and I said that/showed it.   The standard
>> says where.  I was not trying to compile NULL without a definition which I
>> agree it not legal.  If that is what Doug was implying I missed understood
>> him but I note NULL was introduced in Typesetter C /V7 where those compiler
>> s set it to 0 in studio but the ANSI/ISO moved it.
>>
>> On Sun, Sep 20, 2020 at 7:03 PM Norman Wilson <norman at oclsc.org> wrote:
>>
>>> Doug McIlroy:
>>>
>>>
>>>
>>>   To put it more strongly. this is not a legal C source file.
>>>
>>>           char *s = NULL;
>>>
>>>   But this is.
>>>
>>>           char *s = 0;
>>>
>>>
>>>
>>> Clem Cole:
>>>
>>>
>>>
>>>    67)The macro NULL is defined in <stddef.h> (and other headers) as a
>>> null
>>>
>>>    pointer constant; see 7.19.
>>>
>>>
>>>
>>> ====
>>>
>>>
>>>
>>> $ cat null.c
>>>
>>> char *s = NULL;
>>>
>>> $ cat zero.c
>>>
>>> char *s = 0;
>>>
>>> $
>>>
>>>
>>>
>>> zero.c is a legal C program.  null.c is not.  Create
>>>
>>> files exactly as shown and compile them if you don't
>>>
>>> believe me.
>>>
>>>
>>>
>>> Prepend `#include <stddef.h>' (or <stdlib.h> or <stdio.h>)
>>>
>>> to null.c and it becomes legal, but I think that's Doug's
>>>
>>> point: you need an include file.
>>>
>>>
>>>
>>> Personally I prefer to use NULL instead of 0 when spelling
>>>
>>> out a null pointer, because I think it's clearer:
>>>
>>>         if ((buf = malloc(SIZE)) == NULL)
>>>
>>>                 error("dammit andrew");
>>>
>>> though I am willing to omit it when there's no confusion
>>>
>>> about = vs ==:
>>>
>>>         if (*p)
>>>
>>>                 dammit(*p, "andrew");
>>>
>>>
>>>
>>> But that's just a question of style, and Doug's is fine too.
>>>
>>>
>>>
>>> The language does not require the compiler to pre-define
>>>
>>> NULL or to recognize it as a keyword; you have to include
>>>
>>> an appropriate standard header file.
>>>
>>>
>>>
>>> Norman Wilson
>>>
>>> Toronto ON (not 0N nor NULLN)
>>>
>>> --
>> Sent from a handheld expect more typos than usual
>>
>>
>> --
> Sent from a handheld expect more typos than usual
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20200920/3a2baf69/attachment.htm>


More information about the TUHS mailing list