Re: Neatest way to get the end pointer?
- From: vippstar@xxxxxxxxx
- Date: Tue, 5 Feb 2008 18:05:05 -0800 (PST)
On Feb 6, 4:01 am, Peter Nilsson <ai...@xxxxxxxxxxx> wrote:
vipps...@xxxxxxxxx wrote:Ah, I was a bit confused I guess.
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.
However, OP _does_ dereference it. Not in that snipped, but in 4)
4) *(&my_array+ 1) decays to the address of the first element in the.
non-existant array after the current one, which is also the "pend"
address for the array that actually exists.
- Follow-Ups:
- Re: Neatest way to get the end pointer?
- From: Peter Nilsson
- 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
- Re: Neatest way to get the end pointer?
- From: Peter Nilsson
- Neatest way to get the end pointer?
- Prev by Date: Re: A solution for the allocation failures problem
- Next by Date: Re: Neatest way to get the end pointer?
- Previous by thread: Re: Neatest way to get the end pointer?
- Next by thread: Re: Neatest way to get the end pointer?
- Index(es):