简体   繁体   English

如何测试是否支持类似uint64_t的类型?

[英]How to test if a type like uint64_t is supported?

How can I test if a type is supported by a compiler? 如何测试编译器是否支持某种类型? Say like uint64_t. 像uint64_t一样说。 Is there a reference somewhere I can use for learning how to test for any given types? 有什么参考我可以用来学习如何测试任何给定的类型吗?

It is surprisingly hard to find this out via search engine. 很难通过搜索引擎找到它。 I tried "C test for data type" and many other things. 我尝试了“C测试数据类型”和许多其他的东西。

You can check that: 你可以检查:

UINT64_MAX macro is defined after including stdint.h . 在包含stdint.h之后定义UINT64_MAX宏。

If you are not sure if c99 or higher is supported you can also enclose it in a check to __STDC_VERSION__ to be >= 199901L . 如果您不确定是否支持c99或更高版本,您也可以将其括在__STDC_VERSION__的检查中>= 199901L Note that also that __STDC_VERSION__ macro is not present in C89/C90. 请注意,C89 / C90中也不存在__STDC_VERSION__宏。

From the Standard (emphasis mine): 从标准(强调我的):

(C99, 7.18p4) "For each type described herein that the implementation provides,224) 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. " (C99,7.18p4)“对于本文所述的实现提供的每种类型,224)应声明typedef名称并定义相关的宏。 相反,对于本文所述的实现未提供的每种类型,不应声明typedef名称也不定义相关的宏。

Try using it - you'll get a compiler error if it's not there. 尝试使用它 - 如果它不存在,你会得到一个编译器错误。 The types like uint64_t are in stdint.h . uint64_t这样的类型在stdint.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM