2016-03-30

Integer Data Types in C/C++

You may have the same experience, programmers usually define different type names for the same data type. For example, a 16 bits unsigned integer could be defined as UINT16, UINT16_T or uint16. This is confusing and making things complicated. After struggling for so many years, I decide to use the standard types defined in stdint.h.
int8_t
uint8_t
int16_t
uint16_t
int32_t
uint32_t
int64_t
uint64_t
A good C/C++ compiler should has defined stdint.h in RTS (run-time support) library based on the target CPU model.

Btw, it is also good to have unified syntax for all program codes. For example, a user defined type should always be ended with "_t".
typedef struct{
    uint8_t  x;
    uint8_t  y;
}mytype_t;
Where mytype_t is ended with "_t" to indicate that it is a user defined data type.