(Old Wolf) wrote in message news:<. com>...
> Andre Kostur <> wrote:
> > Gianni Mariani <> wrote:
> >
> > > std::vector<char> v;
> > > return foo( & v[0], v.size() );
> > >
> >
> > Offhand I think you've invoked undefined behaviour at the point of you
> > attempting to index element 0 of an empty vector. I don't think that a
> > vector is required to have created _any_ storage for data elements yet...
>
> Annoying. What's the simplest way to obtain a pointer to the start of
> a vector then? It would be silly to require some sort of macro or function
> for this seemingly obvious task.
v.begin() (of type std::vector<char>::iterator) is a pointer to the
first element of the vector. *(v.begin()) is the first element,
though of course in your example this dereference would still be
invalid.
I see your frustration -- you want an array-style pointer to the
beginning of the vector. v.begin() I think is as close as you're
going to get, and it's probably not of the type you want, char*.
http://www.sgi.com/tech/stl/Vector.html is relevant, and SGI's
documentation in general is invaluable.
Best of luck to you.
-Russell Silva