为什么会有这个类型出现呢?
方便代码维护,涉及跨平台,不同得平台有不同的字长。
如:
在C中没有bool型,于是在一个软件中,一个程序员使用int,一个程序员使用short,会比较混乱,最好用一个typedef来定义一个统一的bool,每个程序员都可以用这个别名的bool。
1 .uint8_t / uint16_t / uint32_t / uint64_t 是什么
答:是使用typedef给类型起得别名。
2. uint8_t / uint16_t / uint32_t / uint64_t 占用几个字节
答: 1字节 uint8_t
2字节 uint16_t
4字节 uint32_t
8字节 uint64_t
3. 这些类型在哪里定义
C99标准的C语言硬件为我们定义了这些类型。 按照posix标准,一般整形对应的*_t类型,
具体定义在:/usr/include/stdint.h ISO C99: 7.18 Integer types <stdint.h>
示例:
/* Unsigned. */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
#ifndef __uint32_t_defined
typedef unsigned int uint32_t;
# define __uint32_t_defined
#endif
#if __WORDSIZE == 64
typedef unsigned long int uint64_t;
#else
__extension__
typedef unsigned long long int uint64_t;
#endif
网友评论