3

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?

BoBTFish
  • 19,167
  • 3
  • 49
  • 76
pvl
  • 958
  • 1
  • 6
  • 12
  • 2
    But the standard doesn't actually say anything about internal structure, it's all up to the implementation. However the standard *do* say how the containers should *behave*, and the behavior you worry about (returning a container by value) is well defined. – Some programmer dude Apr 10 '15 at 10:51
  • 1
    Worth noting that libstdc++ (gcc) have put off having C++11 compliant `std::list` (`O(1)` requirement for `size()`) and `std::string` (`O(1)` requirement for `c_str()`) for this very reason. They are waiting for a major version number release for such a breaking change. – BoBTFish Apr 10 '15 at 10:54
  • 2
    This is compiler dependant. In practice the compiler producers try to make those kinds of changes as rarely as possible and advertise when the change will happen. The term for what you are describing is the ABI (Application Binary Interface) http://stackoverflow.com/a/2456882/3807729 – Galik Apr 10 '15 at 10:58

1 Answers1

4

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.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • 1
    Visual C++ breaks the standard library ABI every release. If it affects the person or not is another matter though since not everything breaks. – Rapptz Apr 10 '15 at 11:05
  • 1
    g++ 5 will also break ABI from g++ 4.x – M.M Apr 10 '15 at 11:21