[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

&vec)== &vec[0]?

Ioannis Vranos

9/30/2008 6:15:00 PM

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?

8 Answers

shaun roe

9/30/2008 6:56:00 PM

0

In article <gbtqa8$937$1@ulysses.noc.ntua.gr>,
Ioannis Vranos <ivranos@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

Pete Becker

9/30/2008 7:04:00 PM

0

On 2008-09-30 14:14:32 -0400, Ioannis Vranos
<ivranos@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.

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

puzzlecracker

9/30/2008 7:07:00 PM

0

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

9/30/2008 7:09:00 PM

0

puzzlecracker wrote:
> 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.

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

--
Ian Collins.

Victor Bazarov

9/30/2008 7:37:00 PM

0

puzzlecracker wrote:
> 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.

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

9/30/2008 9:39:00 PM

0

On Sep 30, 3:09 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> puzzlecracker wrote:
> > 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.
>
> &vec is not the same as &vec[0].
>
> --
> Ian Collins.

Opps, I misread Pet's comment.

Juha Nieminen

10/1/2008 2:27:00 PM

0

Pete Becker wrote:
> On 2008-09-30 14:14:32 -0400, Ioannis Vranos
> <ivranos@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

10/1/2008 5:46:00 PM

0

On 2008-10-01 10:27:19 -0400, Juha Nieminen <nospam@thanks.invalid> said:

> Pete Becker wrote:
>> On 2008-09-30 14:14:32 -0400, Ioannis Vranos
>> <ivranos@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.

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.

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