Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can internal STL container structure change in next standard

The problem is here:

//dynamic_module1, compiled with C++11

std::vector<int> some_function();

//dynamic_module2, compiled with C++14

int main() {
    ...//import some_function from dynamic_module1
    std::vector<int> some = some_function();
    ...
}

Is it correct? Do I have any guaranties, that internal structures of STL containers are the same:
1) if modules was compiled by different compilers with same standard version?
2) if modules was compiled by the same compilers, but with different standard versions?

like image 261
pvl Avatar asked Nov 23 '25 00:11

pvl


1 Answers

You don't have any formal guarantees about such compatibility (of standard library containers between two different versions of the standard, or even two different versions of the C++ compiler, and of course of two different C++ compilers).

In practice, if using the same compiler (and version) for the two different standards (e.g. if compiling with the same g++, using g++ -std=c++11 on one hand and using g++ -std=c++14 on the other hand) you are likely (but not sure) to get some compatibility.

Notice that in practice (on Linux/Debian/x86-64), the libstdc++ is dependent of the version of GCC you are using to compile your code. So GCC 4.8 and GCC 4.9 have slightly different standard C++ libraries (which happen to be compatible most of the time but not always).

I have no idea of what is practically happening with Microsoft Visual C++, since I never used Windows.

like image 71
Basile Starynkevitch Avatar answered Nov 24 '25 15:11

Basile Starynkevitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!