Re: Neatest way to get the end pointer?



vipps...@xxxxxxxxx wrote:
Peter Nilsson <ai...@xxxxxxxxxxx> wrote:
... one byte past the end of an array _is_ a valid
pointer.

Hehe, sorry mr Keith for doubting :-P.

However, as you said mr Nilsson, he (the OP) is then
dereferencing it, and invoking undefined behavior.

I never said the OP dereferenced it. The actual code had
been snipped by that point. Here it is...

int *p = my_array;
int const *const pend = my_array + sizeof my_array/
sizeof*my_array;
do *p++ = 42;
while (pend != p);

At no stage is pend dereferenced; and the loop exits on
p == pend, so the address is not dereferenced by p
either.

--
Peter
.