From: Hyman Rosen <hyrosen@mail.com>
Subject: Re: Look what I caught! was re:Ada paper critic
Date: Tue, 18 Jun 2002 10:49:26 -0400
Date: 2002-06-18T10:49:26-04:00 [thread overview]
Message-ID: <3D0F4876.2010201@mail.com> (raw)
In-Reply-To: 3D0E6D8B.C2EF98D3@san.rr.com
Darren New wrote:
> You're probably thinking of what I said, which was that a pointer into an
> array is allowed to be increased to point off the end of the array by one
> element, but you can't access it. You don't necessarily get to point two
> out of bounds, tho.
Right, only one past the end is permitted. As you say, this is used in
algorithms which march a pointer through an array and find it convenient
to post-increment, as in the traditional copying loop of strcpy:
strcpy(char *to, char *from) { while (*to++ = *from++); }
In C++, this approach has been adopted by the STL algorithms. Whenever
they need to operate on a sequence of elements, that sequence is specified
by a half-open range of iterators, [begin, end), which mirrors the pointer
approach, and in fact pointers are valid iterators, so that STL algorithms
can be used on simple arrays. For example, copy is
template<typename T> T copy(T begin, T end, T to)
{ while (begin != end) *to++ = *begin++; return to; }
next prev parent reply other threads:[~2002-06-18 14:49 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-17 17:35 Look what I caught! was re:Ada paper critic Alderson, Paul A.
2002-06-17 18:31 ` Darren New
2002-06-17 21:40 ` Vinzent Hoefler
2002-06-17 23:14 ` Darren New
2002-06-18 14:49 ` Hyman Rosen [this message]
2002-06-18 22:36 ` Vinzent Hoefler
2002-06-18 13:28 ` Marin David Condic
2002-06-24 19:17 ` Vinzent Hoefler
2002-06-18 19:16 ` Kevin Cline
2002-06-18 22:36 ` Vinzent Hoefler
2002-06-19 14:29 ` Wes Groleau
2002-06-19 16:59 ` Darren New
2002-06-19 17:48 ` Wes Groleau
2002-06-19 17:56 ` Darren New
2002-06-19 17:11 ` Frank J. Lhota
2002-06-19 19:31 ` Robert A Duff
2002-06-19 20:02 ` Hyman Rosen
2002-09-24 15:23 ` Matthew Heaney
2002-06-19 19:37 ` Robert A Duff
2002-06-19 13:52 ` Ted Dennison
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox