Pete Becker
10/1/2008 5:46:00 PM
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)