Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a portable value for UINT_MIN?

In limits.h, there are #defines for INT_MAX and INT_MIN (and SHRT_* and LONG_* and so on), but only UINT_MAX.

Should I define UINT_MIN myself? Is 0 (positive zero) a portable value?

like image 208
Ariel Bold Avatar asked Aug 17 '10 04:08

Ariel Bold


1 Answers

It's an unsigned integer - by definition its smallest possible value is 0. If you want some justification besides just common sense, the standard says:

6.2.6.2 Integer types

  1. For unsigned integer types other than unsigned char, the bits of the object representation shall be divided into two groups: value bits and padding bits (there need not be any of the latter). If there are N value bits, each bit shall represent a different power of 2 between 1 and 2^(N−1), so that objects of that type shall be capable of representing values from 0 to 2^(N−1) using a pure binary representation; this shall be known as the value representation. The values of any padding bits are unspecified.
like image 150
Carl Norum Avatar answered Sep 19 '22 12:09

Carl Norum