tech-kern archive

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

Re: NULL pointer arithmetic issues



On Mon, Mar 9, 2020 at 2:53 PM Martin Husemann <martin%duskware.de@localhost> wrote:
>
> On Mon, Mar 09, 2020 at 12:41:37PM -0400, Aaron Ballman wrote:
> > > You could view NULL as a special pointer pointing to an inaccessible
> > > zero sized object. Adding 0 to it still points to the same special
> > > non-object. I guess that is how the C++ folks see it.
> >
> > This wording has always been UB in C. It stopped being UB in C++20 but
> > was UB prior to that. I did not see a core issue pertaining to this
> > (though it's possible I've missed it -- the C++ core issues list is a
> > bit hard to track these days), so I am not certain why this change was
> > made so recently.
>
> AFAICT it has always been well defined in C++, though the wording changed
> a bit. In C++11 (n3337) it is 5.7 note 7: "If the value of 0 is added or
> subtracted from a pointer value, the result compares equal to the original
> pointer value." Same text but moved one note down to 8 in n3797 (C++14).
> N4659 (C++17) makes it explicit for NULL pointers in 8.7 note 7 (as
> Taylor cited earlier in this thread): "If the value 0 is added or subtracted
> from a null pointer value, the result is a null pointer value."

Yes, that's my mistake, sorry about that misinformation! (Taylor also
brought it up off-list.)

~~Aaron

>
> Martin



Home | Main Index | Thread Index | Old Index