Is there any c++ standard paragraph which says that using -1
for this is portable and correct way or the only way of doing this correctly is using predefined values?
I have had a conversation with my colleague, what is better: using -1
for a maximum unsigned integer number or using a value from limits.h
or std::numeric_limits
?
I have told my colleague that using predefined maximum values from limits.h
or std::numeric_limits
is the portable and clean way of doing this, however, the colleague objected to -1
being as same portable as numeric limits, and more, it has one more advantage:
unsigned short i = -1; // unsigned short max
can easily be changed to any other type, like
unsigned long i = -1; // unsigned long max
when using the predefined value from the limits.h
header file or std::numeric_limits
also requires to rewrite it too along with the type to the left.