Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

(&vec)== &vec[0]?

1 view
Skip to first unread message

Ioannis Vranos

unread,
Sep 30, 2008, 2:14:32 PM9/30/08
to
C++03:


Is it always guaranteed that in vector:


vector<int> vec(10);

&vec always points to the first element of the array, for vec.size()> 0?

shaun roe

unread,
Sep 30, 2008, 2:56:26 PM9/30/08
to
In article <gbtqa8$937$1...@ulysses.noc.ntua.gr>,
Ioannis Vranos <ivr...@no.spam.nospamfreemail.gr> wrote:

no

Pete Becker

unread,
Sep 30, 2008, 3:04:19 PM9/30/08
to
On 2008-09-30 14:14:32 -0400, Ioannis Vranos
<ivr...@no.spam.nospamfreemail.gr> said:

No. In fact, it's almost certainly not true. vector dynamically
allocates memory for its stored objects, so &vec[0] has no inherent
relationship to &vec.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

puzzlecracker

unread,
Sep 30, 2008, 3:06:36 PM9/30/08
to
On Sep 30, 2:56 pm, shaun roe <shaun....@wanadoo.fr> wrote:
> In article <gbtqa8$93...@ulysses.noc.ntua.gr>,

>  Ioannis Vranos <ivra...@no.spam.nospamfreemail.gr> wrote:
>
> > C++03:
>
> > Is it always guaranteed that in vector:
>
> > vector<int> vec(10);
>
> > &vec always points to the first element of the array, for vec.size()> 0?
>
> no

Why not? standard guarantees that.

Ian Collins

unread,
Sep 30, 2008, 3:09:20 PM9/30/08
to

&vec is not the same as &vec[0].

--
Ian Collins.

Victor Bazarov

unread,
Sep 30, 2008, 3:37:09 PM9/30/08
to

Where?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

puzzlecracker

unread,
Sep 30, 2008, 5:39:14 PM9/30/08
to

Opps, I misread Pet's comment.

Juha Nieminen

unread,
Oct 1, 2008, 10:27:19 AM10/1/08
to
Pete Becker wrote:
> On 2008-09-30 14:14:32 -0400, Ioannis Vranos
> <ivr...@no.spam.nospamfreemail.gr> said:
>
>> C++03:
>>
>>
>> Is it always guaranteed that in vector:
>>
>>
>> vector<int> vec(10);
>>
>> &vec always points to the first element of the array, for vec.size()> 0?
>
> No. In fact, it's almost certainly not true. vector dynamically
> allocates memory for its stored objects, so &vec[0] has no inherent
> relationship to &vec.

Since we don't know what "vector" he is talking about (since he didn't
say he is talking specifically about std::vector), it could
theoretically be possible for this to be some kind of user-defined
vector class for which &vec and &vec[0] are the same thing.

(Yes, just nitpicking.)

Pete Becker

unread,
Oct 1, 2008, 1:46:00 PM10/1/08
to

Sigh. Communication always relies on assumptions. It's always possible
to make different assumptions and come to different results. The only
issue is whether those other assumptions are reasonable given the
context. Since he didn't say what vector he was talking about, it's
reasonable to assume that it's std::vector.

>
> (Yes, just nitpicking.)

No, just wasting bandwidth playing gotcha.

0 new messages