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.
The UInt64 value type represents unsigned integers with values ranging from 0 to 18,446,744,073,709,551,615.
A uint64_t is standardised in c++ and guarantees 64bits of storage, you need to include stdint. h to use it though. Just in case anyone was interested.
A long is typically 32 bits (but this may very per architecture) and an uint64 is always 64 bits. A native data type which is sometimes 64 bits long is a long long int .
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With