From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3314 invoked from network); 21 Sep 2020 00:11:07 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 21 Sep 2020 00:11:07 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 11EA49CC15; Mon, 21 Sep 2020 10:11:06 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 331D894483; Mon, 21 Sep 2020 10:10:07 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.b="lczsrAjN"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id 8585994483; Mon, 21 Sep 2020 10:10:04 +1000 (AEST) Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by minnie.tuhs.org (Postfix) with ESMTPS id 47704940FD for ; Mon, 21 Sep 2020 10:10:03 +1000 (AEST) Received: by mail-qv1-f48.google.com with SMTP id h1so6452674qvo.9 for ; Sun, 20 Sep 2020 17:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MeJyJ5p8OKcSgI4d5E8FGF8YN9lywU+i7IZBsmCDxMg=; b=lczsrAjN4szRePIya90UegYZ9/2rrNl35TKq5l9ficrceZhqJEVdeGbVyzs/cG7F+p mzFWEG4cLs/QYYdFFtnVVadiqOCgI8sitz6jMBdS9IcvZQW6gWq5sxqfUB/9LT4GjX80 HaBvwlBvAVjy/mIyqjIaIIr9LZ7hsrTZPo3kXzSyTcn8j/Dtii5DvrRisNt6du53zX3I e9krnsfkJVuYKQMHooKXfrAJN662WZNEtN27x1byISXQdhc6q4M+PLsa/X4kCHICiTwF P/zqew/ztR8L7cPv778UsagJuuRGBp9tA/e2gORGpLYIMb7f7j1AhDMhTr2JaHbBs1Hi 3p8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MeJyJ5p8OKcSgI4d5E8FGF8YN9lywU+i7IZBsmCDxMg=; b=fFD70z8jmMP9MdJzvE2F75EqZIllJKceZO8gHMNbWmNJTUw0bvZnFpaEBxfKpQriE1 m+r6C+s89ZSLKxZEd+OpM36lQz08RPSaZi2aszPLavCJjvs8Zdizfdz4R5Orwf4KcMbk OUlVbT8tGTGRhpTSQxguQMCFuXZkrfmlfOdfFaSAQbrMv0XwDHY8p9N4olImccizl5UV j+/9wBYB6SrHP/3nax2b2sqV+1WHqmMA8BuFMC5UWlWArfrk6DSgTdF5V5a71WWTK3u/ TT2aM1ju/NjSq50thvxPD0w+7HVV+dgAaiMf6WFIt5IL9fD6a0w9S/SByxP6PO3KATXW Qtvw== X-Gm-Message-State: AOAM531Ob/vJYm0Dj2uOn9eiNhKANeIORG6O2QeF4MGDXshO3fJbMDbC 5g7s97gv8NAWNYb4IgakLlg8ScGqOo6yg6kg/yxUKQ== X-Google-Smtp-Source: ABdhPJz/f7S4czVGjW7cor2aw475MM8HTC6Oz57M9z9qLcz9gBeRVtyn9Z6AtipweiZSMKak0bQsz51fy1d8HF5VMEg= X-Received: by 2002:ad4:47cc:: with SMTP id p12mr43920565qvw.26.1600647001943; Sun, 20 Sep 2020 17:10:01 -0700 (PDT) MIME-Version: 1.0 References: <20200920230057.C5D1A4422E@lignose.oclsc.org> In-Reply-To: From: Warner Losh Date: Sun, 20 Sep 2020 18:09:49 -0600 Message-ID: To: Clem Cole Content-Type: multipart/alternative; boundary="000000000000f645d905afc7ab34" Subject: Re: [TUHS] reviving a bit of WWB X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: The Eunuchs Hysterical Society Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" --000000000000f645d905afc7ab34 Content-Type: text/plain; charset="UTF-8" To two places: stddef.h and stdlib.h :(. It's interesting to see the different bugs 0, 0L, (char *)0 and (void *)0 expose or hide as definitions of NULL. 0 is fine if sizeof(int) == sizeof(void *). Otherwise varadic function calls break. 0L is the same, but for long. The pointer definitions run into trouble in other contexts since NULL is often incorrectly used as a terminating byte in a string instead of '\0'. (void *) has issues with const pointers, some of which are relevant if you use it in the wrong context. There were quite spirited debates back in the day for which one was best. They all suck. C++ invented a null pointer symbol because it's type rules were enough different than C to make a universal NULL #define impossible. Is that better or worse? Don't know. It's different. Glad to see the null-pointer need not have all zero bits being different than a 0 constant shall be the null-pointer in sufficient detail. Warner On Sun, Sep 20, 2020, 5:54 PM Clem Cole 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 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 (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 ' (or or ) >> >> 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 > --000000000000f645d905afc7ab34 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
To two places: stddef.h and stdlib.h :(.

It's interesting to see the dif= ferent bugs 0, 0L, (char *)0 and (void *)0 expose or hide as definitions of= NULL.

0 is fine if size= of(int) =3D=3D sizeof(void *). Otherwise varadic function calls break. 0L i= s the same, but for long. The pointer definitions run into trouble in other= contexts since NULL is often incorrectly used as a terminating byte in a s= tring instead of '\0'. (void *) has issues with const pointers, som= e of which are relevant if you use it in the wrong context.

There were quite spirited debates bac= k in the day for which one was best. They all suck. C++ invented a null poi= nter symbol because it's type rules were enough different than C to mak= e a universal NULL #define impossible. Is that better or worse? Don't k= now. It's different.=C2=A0

Glad to see the null-pointer need not have all zero bits being diffe= rent than a 0 constant shall be the null-pointer in sufficient detail.

Warner

On Sun, Sep= 20, 2020, 5:54 PM Clem Cole <clemc@ccc= .com> wrote:
Norman NULL has to be defined and I said that/showed it. =C2=A0 The stan= dard says where.=C2=A0 I was not trying to compile NULL without a definitio= n which I agree it not legal.=C2=A0 If that is what Doug was implying I mis= sed 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.=C2=A0

On Sun, Sep 20, 2020 at 7:03 PM Norman Wilson <norman@oclsc.org> = wrote:
Doug McIlroy:


=C2=A0 To put it more strongly. this is not a legal C source file.

= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 char *s =3D NULL;

=C2=A0 But this= is.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 char *s =3D 0;


Clem Cole:



=C2=A0 =C2=A067)The macro NULL is defined in &l= t;stddef.h> (and other headers) as a null

=C2=A0 =C2=A0pointer co= nstant; see 7.19.



=3D=3D=3D=3D



$ cat null.c
char *s =3D NULL;

$ cat zero.c

char *s =3D 0;

$<= br>


zero.c is a legal C program.=C2=A0 null.c is not.=C2=A0 Crea= te

files exactly as shown and compile them if you don't

b= elieve me.



Prepend `#include <stddef.h>' (or <s= tdlib.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:

=C2=A0 =C2=A0= =C2=A0 =C2=A0 if ((buf =3D malloc(SIZE)) =3D=3D NULL)

=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error("dammit andrew")= ;

though I am willing to omit it when there's no confusion
about =3D vs =3D=3D:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (*p)

= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dammit(*p, "an= drew");



But that's just a question of style, and Do= ug's is fine too.



The language does not require the comp= iler 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 han= dheld expect more typos than usual
--000000000000f645d905afc7ab34--