I'm trying to obtain the maximum value of a certain unsigned integer type without including any headers like <limits>
. So I thought I'd simply flip the bits of the unsigned integer value 0.
#include <iostream>
#include <limits>
int main()
{
std::cout << (~0U) << '\n'; // #1
std::cout << (std::numeric_limits< unsigned >::max()) << '\n'; // #2
return 0;
}
I'm not very experienced on the subtle differences between these. Which is why I'm asking if some unexpected behavior or some platform/architecture issues could occur by using the first method.