C++ vs Objective-C – Difference Between UInt8 and uint8_t
c++objective-c
What is the differnce between UInt8 and uint8_t, or UInt16 and unit16_t?
What does the _t imply?
Best Answer
In C99 the available basic integer types (the ones without _t) were deemed insufficient, because their actual sizes may vary across different systems.
So, the C99 standard includes definitions of several new integer types to enhance the portability of programs. The new types are especially useful in embedded environments.
All of the new types are suffixed with a _t and are guaranteed to be defined uniformly across all systems.
int64_t is a Standard C++ type for a signed integer of exactly 64 bits. int64 is not a standard type.
The first C++ standard didn't have fixed-width types. Before int64_t was added to Standard C++, the different compilers all implemented a 64-bit type but they used their own names for it (e.g. long long, __int64, etc.)
A likely series of events is that this project originally would typedef int64 to the 64-bit type for each compiler it was supported on. But once compilers all started to support Standard C++ better, or once the person who wrote the code found out about int64_t, the code was switched over to use the standard name.
uint_least8_t is the smallest type that has at least 8 bits.
uint_fast8_t is the fastest type that has at least 8 bits.
You can see the differences by imagining exotic architectures. Imagine a 20-bit architecture. Its unsigned int has 20 bits (one register), and its unsigned char has 10 bits. So sizeof(int) == 2, but using char types requires extra instructions to cut the registers in half. Then:
uint8_t: is undefined (no 8 bit type).
uint_least8_t: is unsigned char, the smallest type that is at least 8 bits.
uint_fast8_t: is unsigned int, because in my imaginary architecture, a half-register variable is slower than a full-register one.
Best Answer
In C99 the available basic integer types (the ones without _t) were deemed insufficient, because their actual sizes may vary across different systems.
So, the C99 standard includes definitions of several new integer types to enhance the portability of programs. The new types are especially useful in embedded environments.
All of the new types are suffixed with a _t and are guaranteed to be defined uniformly across all systems.
For more info see the fixed-width integer types section of the wikipedia article on Stdint.