I noticed that clang ++ contains the missing header - <limits> on the Mac, and g ++ shows errors about this on Linux. Now I wonder why clang does this, but gcc doesn't. And how can I get clang not to do this.
Here is an example of code that compiles clang on a Mac, but not using gcc on Linux:
#include <iostream> using namespace std; int main() { cout << "int max: " << numeric_limits<int>::max() << endl; }
UPD
I looked through the libraries, and here is what I found.
Internally, <iostream> includes <istream> , which defines the >> operator for different types. <istream> wants to know the limits for the short , int and streamsize .
clang ++ uses the standard libC ++ library , which uses the std::numeric_limits class template <limits> in <istream> for this purpose. That's why this header is automatically included when <iostream> turned on.
g ++ uses the standard libstdC ++ library , which uses __gnu_cxx::__numeric_traits class template from <ext/numeric_traits.h> instead of using <limits> in <istream> ( <bits/istream.tcc> ). There is a comment in this header that explains why they do not use <limits> :
<limits> big and we don't turn it on
Used compilers:
> clang++ --version Apple LLVM version 8.0.0 (clang-800.0.42.1) $ g++ --version g++ (Debian 4.9.2-10) 4.9.2
c ++ gcc include clang
Kostiantyn ponomarenko
source share