Consider the following C++ program:
#include <iostream>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> v(2, std::string(24,0));
for (auto& s : v) {
std::cout << "Address: " << (void*)s.data() << std::endl;
}
}
I would expect each string in the vector to point to a different memory region, but with both gcc 6.3.0 and 8.2.1 when compiling with -D_GLIBCXX_USE_CXX11_ABI=0
, they show the same address. (when compiling without the flag, they show different addresses). Why is that?