Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以在编译时确定实现是否提供精确宽度的整数类型?示例代码(需要):
#include <stdint.h> #if HAS_EXACT_WIDTH_INTEGER_TYPES uint32_t i; #else /* handle the case */ #endif
问题的原因:编写适应性代码,如果实现不提供精确宽度的整数类型,则不会导致编译时错误。
C11/C17 7.20p4:
对于实现提供的此处描述的每种类型,261)<stdint.h>应声明该 typedef 名称并定义相关联的宏。相反,对于此处描述的实现未提供的每种类型,<stdint.h>不应声明该typedef名称,也不应定义关联的宏。实现应提供那些描述为“必需”的类型,但不需要提供任何其他类型(描述为“可选”)。
<stdint.h>
typedef
即uint32_t存在iff #defined UINT32_MAX等。
uint32_t
#defined UINT32_MAX