vector, raw pointer & msvc debugger
От: 10000.monkeys Россия  
Дата: 25.12.18 10:14
Оценка:
Почему отладчик студии показывает разные значения элементов для vector<char> и (char*)&vector[0]?

std::vector<char> buffer;
buffer.resize(2, 0);


buffer 0x0095ef64 { size=2 } std::vector<char,std::allocator<char> > *
[capacity] 2 int
[allocator] allocator std::_Compressed_pair<std::_Wrap_alloc<std::allocator<char> >,std::_Vector_val<std::_Simple_types<char> >,1>
[0] 0 '\0' char
[1] 0 '\0' char

(char*)&buffer[0],2 0x0095ef64 "Ёx" char[2]
[0] -88 'Ё' char
[1] 120 'x' char
vector pointer msvc
Re: vector, raw pointer & msvc debugger
От: EreTIk EreTIk's Box
Дата: 25.12.18 17:50
Оценка:
Здравствуйте, 10000.monkeys, Вы писали:

1M>Почему отладчик студии показывает разные значения элементов для vector<char> и (char*)&vector[0]?


  Скрытый текст
1M>
1M>std::vector<char> buffer;
1M>buffer.resize(2, 0);
1M>


1M>buffer 0x0095ef64 { size=2 } std::vector<char,std::allocator<char> > *

1M>[capacity] 2 int
1M>[allocator] allocator std::_Compressed_pair<std::_Wrap_alloc<std::allocator<char> >,std::_Vector_val<std::_Simple_types<char> >,1>
1M>[0] 0 '\0' char
1M>[1] 0 '\0' char

1M>(char*)&buffer[0],2 0x0095ef64 "Ёx" char[2]

1M>[0] -88 'Ё' char
1M>[1] 120 'x' char


Может старая студия? Например 15.9.4:
  Скрытый текст
-        buffer    { size=0x00000002 }    std::vector<char,std::allocator<char> >
        [capacity]    0x00000002    int
+        [allocator]    allocator    std::_Compressed_pair<std::allocator<char>,std::_Vector_val<std::_Simple_types<char> >,1>
        [0x00000000]    0x00 '\0'    char
        [0x00000001]    0x00 '\0'    char
-        [Raw View]    {...}    std::vector<char,std::allocator<char> >
-        std::_Vector_alloc<std::_Vec_base_types<char,std::allocator<char> > >    {_Mypair=allocator }    std::_Vector_alloc<std::_Vec_base_types<char,std::allocator<char> > >
-        _Mypair    allocator    std::_Compressed_pair<std::allocator<char>,std::_Vector_val<std::_Simple_types<char> >,1>
-        [Raw View]    {_Myval2={_Myfirst=0x00c34e88 "" _Mylast=0x00c34e8a "ээээГ" _Myend=0x00c34e8a "ээээГ" } }    std::_Compressed_pair<std::allocator<char>,std::_Vector_val<std::_Simple_types<char> >,1>
        std::allocator<char>    {...}    std::allocator<char>
-        _Myval2    {_Myfirst=0x00c34e88 "" _Mylast=0x00c34e8a "ээээГ" _Myend=0x00c34e8a "ээээГ" }    std::_Vector_val<std::_Simple_types<char> >
+        std::_Container_base12    {_Myproxy=0x00c35b58 {_Mycont=0x006ff9e0 {_Myproxy=0x00c35b58 {_Mycont=0x006ff9e0 {_Myproxy=0x00c35b58 {...} } ...} } ...} }    std::_Container_base12
+        _Myfirst    0x00c34e88 ""    char *
+        _Mylast    0x00c34e8a "ээээГ"    char *
+        _Myend    0x00c34e8a "ээээГ"    char *


-        (char *)&buffer[0],2    0x00c34e88 "\0\0"    char[0x00000002]
        [0x00000000]    0x00 '\0'    char
        [0x00000001]    0x00 '\0'    char
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.