Question

with this code:

#include <iostream>
#include <list>

int main() {
    std::cout << sizeof(std::list<void*>) << std::endl;
};

I managed to notice that on GCC 4.7 the size of std::list<void*> on C++98 is 16 bytes, and its size on C++11 is 24 bytes.

I was wondering what changed on std::list that made it bigger.

Was it helpful?

Solution

C++11 requires list::size() to execute in constant time. GCC made this possible by adding the size as a data member. GCC did not do so for C++98 mode, because that would break binary compatibility.

Don't mix code compiled in C++98 mode with code compiled in C++11 mode. It doesn't work.

Update: apparently, the GCC folks had a change of heart, and C++11 conformance is less important than maintaining compatibility for now, so list::size() will no longer execute in constant time in GCC 4.7.2. It will in a future version, in both C++98 and C++11 modes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top