c - 64位处理器的uint16_t和unsigned short int incase有什么区别?

标签 c linux

我开始使用 uint16_t 类型的变量,但由于我的项目限制,我无法使用该数据类型。是否可以使用 unsigned short int 而不是 uint16_t? 我不知道他们两个之间的区别。有人可以澄清一下吗?

最佳答案

uint16_t 是无符号 16 位整数。

unsigned short int 是无符号短整数,但大小取决于实现。该标准只说它至少是 16 位(即 UINT_MAX 的最小值是 65535)。实际上,它通常是 16 位的,但您不能保证这一点。

注意:

  1. 如果您需要可移植的无符号 16 位整数,请使用 uint16_t
  2. inttypes.hstdint.h 都是在C99 中引入的。如果您使用的是 C89,请定义您自己的类型。
  3. uint16_t 在某些实现中可能不提供(请参阅下面的引用),但 unsigned short int 始终可用。

引用:C11(ISO/IEC 9899:201x) §7.20 整数类型

For each type described herein that the implementation provides) shall declare that typedef name and define the associated macros. Conversely, for each type described herein that the implementation does not provide, shall not declare that typedef name nor shall it define the associated macros. An implementation shall provide those types described as ‘‘required’’, but need not provide any of the others (described as ‘optional’’).

关于c - 64位处理器的uint16_t和unsigned short int incase有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17693445/

相关文章:

ios - 更改 EXIF 数据以正确识别 iPhone

linux - 如何仅为当前 session 设置 vi 选项?

c - 参数未定的函数指针

c - 分配内部有数组的结构体数组

linux - install.packages ("devtools") 在 R 3.0.2 上在 Ubuntu 14.04 中失败

c++ - 链接 netpbm 库时出现问题

linux - 如果绑定(bind)到 localhost/127.0.0.1 而不是外部,OpenJDK 7 AsynchronousServerSocketChannel 仅接受 localhost

C 错误, "' 预期为 '=' ',' ';' 、 'asm' 或 '__attribute__' 之前 'Bufferpar' "

c - malloc 和 free 的错综复杂

c - memcpy 问题将负值从 int8_t 转换为 int16_t