關於int8_t,uint8_t.....等數據類型的理解


實習中,今天在看公司源碼的時候,發現前輩給的代碼都是這樣的

typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef word_t word16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef dword_t dword32;
typedef int64_t int64;
typedef uint64_t uint64;
typedef uint32 color_t;

typedef time_t time64;
typedef wchar_t char16;//寬字符
typedef char    char8;

 身為小白的我內心是這樣的      ???????

查找后得出了結論,其實這些都是已經被typedef過的類型:

typedef signed char int8_t;
typedef unsigned char uint8_t;

typedef int int16_t;
typedef unsigned int uint16_t;

typedef long int32_t;
typedef unsigned long uint32_t;

typedef long long int64_t;
typedef unsigned long long uint64_t;   

  這些包含在inttypes.h頭文件,據說這樣做的原因是方便移植,比如int8就是8位大小占一字節,int32,,32位大小4字節… 
這樣相對應的占位符也就清楚了:

char /unsigned char: %c
int : %d 
unsigned int: %u  
long: %ld; 
unsigned long:%lu
long long: %lld(%l64d)
unsigned long long:%Ilu(%l64u)

 即:

int8_t:%c;
uint8_t:%c;

int16_t: %d;
uint16_t:%u;

int32_t:%ld;
uint32_t:%lu;

int64_t:%lld(%l64d);
uint64_t:%llu(%l64u);

資料:https://blog.csdn.net/eusia/article/details/76401235


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM