From: Clem Cole <clemc@ccc.com>
To: Warner Losh <imp@bsdimp.com>
Cc: The Eunuchs Hysterical Society <tuhs@tuhs.org>
Subject: Re: [TUHS] reviving a bit of WWB
Date: Sun, 20 Sep 2020 21:05:23 -0400 [thread overview]
Message-ID: <CAC20D2NmRRKc=bWE25_B+rFSQpRsBJFbiou9RYmc33BRGtrubQ@mail.gmail.com> (raw)
In-Reply-To: <CANCZdfo+LL-xfk6rygrZaremzNfYEmxAmMPaeuiOhrV9uCk3ag@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3462 bytes --]
Yep. They all suck. As Dennis said, “C is quirky” and part of the issue
is HW is even more so. Clem
On Sun, Sep 20, 2020 at 8:10 PM Warner Losh <imp@bsdimp.com> wrote:
> 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 <clemc@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@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
[-- Attachment #2: Type: text/html, Size: 4625 bytes --]
next prev parent reply other threads:[~2020-09-21 1:06 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-20 23:00 Norman Wilson
2020-09-20 23:53 ` Clem Cole
2020-09-21 0:00 ` Clem Cole
2020-09-21 2:24 ` John Cowan
2020-09-21 0:09 ` Warner Losh
2020-09-21 1:05 ` Clem Cole [this message]
2020-09-21 5:55 ` Steve Nickolas
2020-09-21 5:59 ` Warner Losh
2020-09-21 18:40 ` Paul Winalski
2020-09-21 19:56 ` Dan Cross
2020-09-21 20:50 ` John Cowan
2020-09-21 21:22 ` Rob Pike
2020-09-21 21:57 ` Clem Cole
2020-09-21 23:56 ` John Cowan
2020-09-22 0:54 ` Richard Salz
2020-09-21 21:39 ` Steve Nickolas
-- strict thread matches above, loose matches on Subject: below --
2020-09-25 14:19 Doug McIlroy
2020-09-28 17:35 ` Angelo Papenhoff
2020-09-20 22:51 Norman Wilson
2020-09-19 1:51 Doug McIlroy
2020-09-20 18:42 ` arnold
2020-09-20 19:28 ` Will Senn
2020-09-20 20:12 ` Steve Nickolas
2020-09-20 20:26 ` Doug McIlroy
2020-09-20 20:57 ` Doug McIlroy
2020-09-20 22:13 ` Clem Cole
2020-09-21 20:43 ` Steffen Nurpmeso
2020-09-20 20:58 ` Steve Nickolas
2020-09-20 21:33 ` Brantley Coile
2020-10-07 5:43 ` scj
2020-09-20 21:35 ` John Cowan
2021-02-02 23:08 ` Greg A. Woods
2021-02-02 23:47 ` Larry McVoy
2021-02-03 0:11 ` Dave Horsfall
2021-02-03 0:19 ` Larry McVoy
2021-02-03 2:04 ` Richard Salz
2021-02-03 3:32 ` Dave Horsfall
2021-02-03 4:32 ` M Douglas McIlroy
2021-02-03 11:27 ` Peter Jeremy via TUHS
2021-02-03 20:09 ` Dave Horsfall
2021-02-03 20:13 ` Niklas Karlsson
2021-02-03 23:46 ` Tom Lyon
2021-02-03 22:19 ` Dave Horsfall
2021-02-03 22:55 ` M Douglas McIlroy
2020-09-20 22:15 ` Clem Cole
2020-09-20 22:47 ` John Cowan
2020-09-21 20:48 ` Steffen Nurpmeso
2020-09-21 20:46 ` Steffen Nurpmeso
2020-09-24 2:25 ` Dave Horsfall
2020-09-24 2:33 ` Clem Cole
2020-09-27 5:54 ` Dave Horsfall
2020-09-24 17:19 ` Paul Winalski
2020-09-24 18:17 ` John Cowan
2020-10-07 5:47 ` scj
2020-10-07 9:20 ` arnold
2020-10-08 0:27 ` Dave Horsfall
2020-10-08 3:08 ` John Cowan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAC20D2NmRRKc=bWE25_B+rFSQpRsBJFbiou9RYmc33BRGtrubQ@mail.gmail.com' \
--to=clemc@ccc.com \
--cc=imp@bsdimp.com \
--cc=tuhs@tuhs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).