I just stumbled upon the type u_int8_t
because it did not compile in Windows+MinGW (but compiled fine under Linux). According to this site the C++11 standard defines the type uint8_t
. I just used the latter and everything worked.
The questions that arised are:
u_int8_t
and uint8_t
? u_int8_t
?uint8_t
will be present if I use a C++11 compiler (on different OS or architectures)?intX_t
and uintX_t
)?uint32_t is used when you must have a 32 bit unsigned. int or unsigned int for general purposes when you don't need a guaranteed size and unsigned only if you can ensure that you won't have negative numbers.
Unsigned Integers (often called "uints") are just like integers (whole numbers) but have the property that they don't have a + or - sign associated with them. Thus they are always non-negative (zero or positive). We use uint's when we know the value we are counting will always be non-negative.
The unsigned int can contain storage size either 2 or 4 bytes where values ranging from [0 to 65,535] or [0 to 4,294,967,295]. The format specifier used for an unsigned int data type in C is “ %u ”.
Unsigned int data type in C++ is used to store 32-bit integers. The keyword unsigned is a data type specifier, which only represents non-negative integers i.e. positive numbers and zero.
Is there any difference between
u_int8_t
anduint8_t
?
u_int8_t
is just a very old name that was not standardised. Avoid it.
Is there a reason (besides legacy code) to use
u_int8_t
?
Suicide by coworker.
Is it safe to assume that
uint8_t
will be present if I use a C++11 compiler (on different OS or architectures)?
The C++ standard requires it to be present on all implementations that have an unsigned 8-bit type available (today that means everything that is not exotic).
Are the answers to the above questions also valid for the other types (
intX_t
anduintX_t
)?
Pretty much, yes.
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