Re: Neatest way to get the end pointer?
- From: Peter Nilsson <airia@xxxxxxxxxxx>
- Date: Tue, 5 Feb 2008 18:01:51 -0800 (PST)
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
.
- Follow-Ups:
- Re: Neatest way to get the end pointer?
- From: vippstar
- Re: Neatest way to get the end pointer?
- References:
- Neatest way to get the end pointer?
- From: Tomás Ó hÉilidhe
- Re: Neatest way to get the end pointer?
- From: vippstar
- Re: Neatest way to get the end pointer?
- From: Keith Thompson
- Re: Neatest way to get the end pointer?
- From: vippstar
- Re: Neatest way to get the end pointer?
- From: Peter Nilsson
- Re: Neatest way to get the end pointer?
- From: vippstar
- Neatest way to get the end pointer?
- Prev by Date: Re: stdin (keyboard) to file
- Next by Date: Re: A solution for the allocation failures problem
- Previous by thread: Re: Neatest way to get the end pointer?
- Next by thread: Re: Neatest way to get the end pointer?
- Index(es):