c - 是否可以在编译时确定实现是否提供精确宽度的整数类型?

标签 c c11 stdint c17

是否可以在编译时确定实现是否提供精确宽度的整数类型?示例代码(需要):

#include <stdint.h>

#if HAS_EXACT_WIDTH_INTEGER_TYPES
uint32_t    i;
#else
/* handle the case */
#endif

问题的原因:编写适应性强的代码,如果实现不提供精确宽度的整数类型,则不会导致编译时错误。

最佳答案

C11/C17 7.20p4 :

  1. For each type described herein that the implementation provides, 261) <stdint.h> shall declare that typedef name and define the associated macros. Conversely, for each type described herein that the implementation does not provide, <stdint.h> 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'').

uint32_t存在 iff #defined UINT32_MAX

关于c - 是否可以在编译时确定实现是否提供精确宽度的整数类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68522160/

相关文章:

c - 在 C11 中链接翻译单元的规则是什么?

c - 将 alignas() 应用于 C 中的整个结构

c - C 类型之间的区别 int32_t int_least32_t 等

c++ - 获得两倍宽的字体

c - 如何对我的数据进行排序?

c - 比较指针与静态变量的行为是什么?

c# - Interop 导致 Unity 崩溃

c - 信息 C5012 : loop not parallelized due to reason ‘1007’

c - 在另一个代码中访问变量

c++ - 为什么每个人都对标准 C 类型进行 typedef?