Whats the difference between UInt8 and uint8_t
C++Objective CCC++ Problem Overview
What is the differnce between UInt8
and uint8_t
, or UInt16
and unit16_t
?
What does the _t
imply?
C++ Solutions
Solution 1 - C++
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.
Solution 2 - C++
The main difference is that the uintX_t
types are standard C defined by C99 and later while UIntX
is not. This has implications for how portable the code is. Code using uintX_t
types can be compiled on any standard C compiler without any other dependencies. Code that uses UIntX
on the other hand, must either define those types itself, or depend on some library or framework that does so.
I don't think Objective-C as such defines any extra integer types, but it may well be that your framework (Coacoa, OpenStep?) does so. If your code makes no sense outside of the framework, use what's idiomatic in the framework context. Otherwise try to stick to the standard types.
Solution 3 - C++
normally they are used as a typedef datatypes. "_t" stand for a typedef datatype. we give such name so that they can be used and read easily across all the file or huge code base.
UInt8 and uint8_t - Char
typedef unit8_t unsigned char
UInt16 and unit16_t
typedef unit16_t unsigned int ( on a 16 bit compiler)