For C++, I believe you should preferably use the numeric_limits
template from the <limits>
header :
if (foo == std::numeric_limits<unsigned int>::max())
/* ... */
For C, others have already pointed out the <limits.h>
header and UINT_MAX
.
Apparently, "solutions which are allowed to name the type are easy", so you can have :
template<class T>
inline bool is_max_value(const T t)
{
return t == std::numeric_limits<T>::max();
}
[...]
if (is_max_value(foo))
/* ... */
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…