Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test if a type like uint64_t is supported?

Tags:

c

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.

like image 868
JustTired Avatar asked Dec 29 '12 01:12

JustTired


People also ask

What does UInt64_ t mean in C?

The UInt64 value type represents unsigned integers with values ranging from 0 to 18,446,744,073,709,551,615.

Is there uint64_t?

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.

Is Ulong a UInt64?

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 .


2 Answers

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

like image 180
ouah Avatar answered Sep 24 '22 04:09

ouah


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

like image 31
Carl Norum Avatar answered Sep 24 '22 04:09

Carl Norum