如果您希望代码能够编译为C,那么您几乎需要使用<limits.h>
.如果你正在编写C++,那么最好使用C++ <limits>
头文件.后者允许您编写可在模板中使用的代码,这些模板无法与C头实际重复:
template <class T>
class mytemplate {
T x;
void somefunc() { x = std::numeric_limits<T>::max(); } // or whatever...
};
Run Code Online (Sandbox Code Playgroud)