I keep trying different search terms for this question and I'm just finding noise on both Google and stackoverflow. If I write code using C++'s standard library (std), is it all basically guaranteed to compile for Windows, Mac, and Linux (and hopefully work as intended)?
The standard defines what it means to be a C++ compiler, and all compilers claiming to be C++ should conform to the standard; any that don't can be considered buggy. All of the major compilers try their best to be conforming.
There are multiple standards to be concerned with here - C++98, C++03, C++11, C++14, C++17, and work has started on C++20. Sometimes the features in the latest current standard won't be implemented in every compiler. If you stick to C++03 you should find wide conformity.
Everything in the std
namespace should be part of the standard, by definition.
Code is guaranteed to compatible across all standards-compliant compilers/platforms, but it is important to note that the ABI is not, i.e. you may not assume it safe to link across binaries created from different compilers/versions/platforms.
In practice, this means don't pass STL objects like string
or vector
around across from one library to another, unless you compiled both in the exact same way at the exact same time. This is especially important when passing pointers to dynamic data: you can't use shared_ptr
in your library APIs unless you can meet the said-guarantee, you'll need to use regular pointers instead.
The argument is that anything that is not STL compliant is not C++ compliant, and so, in one respect, yes, all STL is cross-platform.
However, be aware that some part of STL are allowed to be implementation defined. For example see type_info::name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With