本文参考:
https://blog.csdn.net/smallfish_love/article/details/50782905
arm平台下的数据类型重定义
typedef char s8;
typedef unsigned char u8;
typedef short s16;
typedef unsigned short u16;
typedef int s32;
typedef unsigned int u32;
typedef float f32;
typedef signed long long s64;
typedef unsigned long long u64;
ppc平台下的数据类型重定义
typedef signed char s8;
typedef unsigned char u8;
typedef signed short s16;
typedef unsigned short u16;
typedef signed int s32;
typedef unsigned int u32;
typedef signed long s64;
typedef unsigned long u64;
由于以上数据类型是针对不同体系结构定义的,因此在任何平台下对其用sizeof运算的结果是不变的,是确定长度的数据类型。
但是以上这些数据类型只能在内核空间使用,在Linux用户空间中,如果要使用确定长度的数据类型,应该使用上述类型加“__(双下划线)”版本,如__u32、__u16、__u8。其余Linux中还存在_t后缀的重定义数据类型。
代码:
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <signal.h>
#include <stdio.h>
typedef char s8;
typedef unsigned char u8;
typedef short s16;
typedef unsigned short u16;
typedef int s32;
typedef unsigned int u32;
typedef float f32;
typedef signed long long s64;
typedef unsigned long long u64;
int main(int argc, const char * argv[]) {
printf("s8:%d\n",sizeof(s8));
printf("u8:%d\n",sizeof(u8));
printf("s16:%d\n",sizeof(s16));
printf("u16:%d\n",sizeof(u16));
printf("s32:%d\n",sizeof(s32));
printf("u32:%d\n",sizeof(u32));
printf("s64:%d\n",sizeof(s64));
printf("u64:%d\n",sizeof(u64));
printf("unsigned long:%d\n",sizeof(unsigned long));
return 0;
}