简体   繁体   中英

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. 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.

You can check that:

UINT64_MAX macro is defined after including stdint.h .

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 . Note that also that __STDC_VERSION__ macro is not present in C89/C90.

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. "

Try using it - you'll get a compiler error if it's not there. The types like uint64_t are in stdint.h .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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