Is it the same? If no: what is the difference? If yes then why do you need this type?
unsigned int is the unsigned integer type, and will match in size with int . That means that it's at least 16 bits in size, although on most modern+popular platforms, it'll be 32 bits. Uint32 (or uint32_t ) is a 32-bit unsigned integer.
uint32_t is a numeric type that guarantees 32 bits. The value is unsigned, meaning that the range of values goes from 0 to 232 - 1.
Type of unsigned long is different from uint32_t and uint64_t on Windows (VS2010) Bookmark this question. Show activity on this post. assuming of course that long is not longer than 64bits.
There is no difference. unsigned and unsigned int are both synonyms for the same type (the unsigned version of the int type).
uint32_t
(or however pre-C++11 compilers call it) is guaranteed to be a 32-bit unsigned integer; unsigned int
is whatever unsigned integer the compiler likes best to call unsigned int
, as far as it meets the requirements of the standard (which demands for it a 0-65535 minimum range).
Like int
, unsigned int
typically is an integer that is fast to manipulate for the current architecture (normally it fits into a register), so it's to be used when a "normal", fast integer is required.
uint32_t
, instead, is used when you need an exact-width integer, e.g. to serialize to file, or when you require that exact range or you rely on unsigned overflow to happen exactly at 2^32-1
.
For example, on a 16 bit-processor unsigned int
will typically be 16 bits wide, while uint32_t
will have to be 32 bits wide.
Incidentally, as pointed out by @Marc Glisse, while unsigned int
is always present, uint32_t
is not mandatory - a particular compiler implementation may not provide it. This is mostly because not all platforms can easily provide such a type (typically DSPs with weird word sizes).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With