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 09, 2020 at 09:38:31AM -0400, Aaron Ballman wrote:
> The way I read this is:
>
> "If the pointer operand points to an element of an array object" -- it
> does not (null is not a valid array object).
> "Moreover, if the expression P points to the last element of an array
> object" -- it does not (null is not a valid array object).
> "If both the pointer operand and the result point to elements of the
> same array object, or one past the last element of the array
> object..." -- it does not (there is no valid array so they cannot
> point to elements of the same array).
All fine.
> "...otherwise, the behavior is undefined." -- this is where we hit the UB.
But it started with "If the pointer operand points to an element of an
array object" and my reading is that the whole section does not apply.
NULL is special, and we did not change it's value, so it stays a NULL
pointer. The section you cited just does not tell anything about arithmetic
on NULL pointers - and the wording makes it sound like this is more an
oversight than a concious descision.
Eespecially adding or subtracting zero.
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.
Martin
Home |
Main Index |
Thread Index |
Old Index