[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dereferencing NULL. (Was: [PATCH v3] NULL.3const: Add documentation

From: Alejandro Colomar
Subject: Re: Dereferencing NULL. (Was: [PATCH v3] NULL.3const: Add documentation for NULL)
Date: Tue, 26 Jul 2022 21:13:19 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.0.2

Hi Ralph,

On 7/26/22 14:25, Ralph Corderoy wrote:

Its long been the case that straying into undefined behaviour allows a
compiler to optimise away what is stated above as ‘almost certain’,

     Dereferencing a NULL Pointer: contrary to popular belief,
     dereferencing a null pointer in C is undefined.
     It is not defined to trap...
     NULL pointer dereferences being undefined enables a broad range of
     In C-based languages, NULL being undefined enables a large number of
     simple scalar optimizations that are exposed as a result of macro
     expansion and inlining.

Yeah, that's my fear.

I think the text in v5 will be a useful middleground.  Correct me if not.

But consider the broader ISO C scenario (or old POSIX.1-2001), where
NULL isn't defined to be (void*)0.  There it isn't so obvious that 0
would also represent a null pointer.

On a machine which uses a non-zero bit pattern as its NULL pointer,
the constant 0 in a pointer context will be that non-zero bit pattern.

Yeah. Although, I'm considering completely removing any reference to that, on the grounds that that doesn't affect POSIX systems because even though POSIX doesn't make such guarantees yet, all existing POSIX systems de-facto use all 0s to represent a null pointer _and_ a I've been told (I can't find the source now) that a future revision of POSIX is going to make such guarantee.

So, poor non-POSIX users have that problem, but that not our problem.

I find the content of this man page for NULL seems confused.  It's
mixing reference material from standards with tutorial information for
beginners at C programming.  I think a man page should contain succinct
reference material and leave introductory or exploratory material to
accompanying papers.  Do the Linux man pages ship accompanying papers,
as the original ‘Editions’ of Unix did?  Perhaps that's an opening and
less constrained format?

No, we don't have accompanying papers.

So, I'd like to document what is relevant to programmers. For both beginners and experts. I'll still try to be very succinct, and thank you all for helping me trim the page down a lot.

For accompanying papers, these days, we have the standards documents themselves, and also the many programming online forums, so I don't want to be adding yet another documentation format.



Alejandro Colomar

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]