谁能解释一下 uint8_t
和 __u8
之间的区别?
我知道 uint8_t
是在 stdint.h 中定义的,它们在每个 unix 系统上都可用。
/* Unsigned. */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
...
如果我使用它们,那么我的意图是显而易见的。
现在我偶然发现了 __u8
和 __u16
类型。对我来说似乎是一样的。
其中一些类型在 linux/types.h 中定义
#ifdef __CHECKER__
#define __bitwise__ __attribute__((bitwise))
#else
#define __bitwise__
#endif
#ifdef __CHECK_ENDIAN__
#define __bitwise __bitwise__
#else
#define __bitwise
#endif
typedef __u16 __bitwise __le16;
typedef __u16 __bitwise __be16;
typedef __u32 __bitwise __le32;
...
我没有找到 __u8
但我仍然可以使用它并且它的行为类似于 uint8_t。
在性能或内存消耗方面是否存在差异?
感谢您的帮助:)
最佳答案
uint<i>n</i>_t
是 C99(在 <stdint.h>
中)和 C++11(在 <cstdint>
中)标准指定的类型定义*。所有新编译器都提供这些,并且很容易为少数古老的编译器轻松获得适当的定义,因此为了可移植性,请始终使用它。
__u<i>n</i>
是早于这些标准的特定于 Linux 的 typedef。它们不是可移植的。双下划线用于表示非标准定义。
* 对于 8、16、32 和 64,应定义它们如果编译器具有该大小的类型,则可以定义其他类型。
关于c++ - __u8 和 uint8_t 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16232557/