c++ - __u8 和 uint8_t 之间的区别

标签 c++ types stdint

谁能解释一下 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/

相关文章:

c++ - VS 错误 C2664(从函数返回字符串)C++

php - MySQL/PHP - 在数字周围加上引号会破坏任何查询吗?

.net - Vb.net接口(interface),make方法只接受相同类型的实例作为参数

c - stdint.h 和 inttypes.h 之间的区别

cuda - 在 CUDA NVRTC 代码中包含 C 标准头文件

C++ LibCurl - 将 CURLcode 转换为 CString

c++ - 使用IOS成员(member)进行格式化

c++ - 使用 C++ 处理 zip 存档

haskell - 数据类型列表 : "could not deduce (a ~ SomeType) from the context (SomeTypeclass a)"

c - stdint.h 和 C99