Seebs <usenet-> writes:
> On 2010-06-16, Richard Heathfield <> wrote:
>> Yes. Since a null pointer doesn't point to an object, neither it nor the
>> result can point to "elements of the same array object, or one past the
>> last element of the array object", and therefore the behaviour is undefined.
>
> Okay, I haven't had any caffeine today, but.
>
> What tells us that a null pointer cannot point one past the last
> element of an array object?
>
> I agree that nothing tells us that it *does* point one past the last
> element of an array object. But could it?
In theory, I think so.
C99 6.3.2.3p3:
If a null pointer constant is converted to a pointer type,
the resulting pointer, called a _null pointer_, is guaranteed
to compare unequal to a pointer to any object or function.
An implementation for which a null pointer is equal to a pointer just
past the end of some object could break some seemingly reasonable
code (but only if it happens to be operating on that one object),
but I don't see anything in the standard that forbids it.
An almost-plausible scenario: A null pointer is represented as
all-bits-zero. Automatic objects are allocated on The Stack, which
grows from high addresses to low, and starts at the top end of the
address space, address 0xffffffff. Pointer arithmetic quietly wraps
around from 0xffffffff to 0. The last byte of the first allocated
object in the program (perhaps argc, perhaps the string pointed to
by argv[0], perhaps something else) occupies byte 0xffffffff.
I doubt that any such implementations actually exist.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"