Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if __uint128_t is defined [duplicate]

We can use the preprocessor to know if unsigned long long is defined:

#include <limits.h>

#ifndef ULLONG_MAX
typedef unsigned long t_mask; 
#else
typedef unsigned long long t_mask;
#endif

But how to know if __uint128_t is defined?

like image 232
David Ranieri Avatar asked Aug 30 '13 11:08

David Ranieri


4 Answers

You can try the following. I do not know how reliable this is, but it might be the easiest way.

#ifdef __SIZEOF_INT128__
    // do some fancy stuff here
#else
    // do some fallback stuff here
#endif
like image 87
firefexx Avatar answered Nov 05 '22 07:11

firefexx


find your cc1 in the /usr/libexec/gcc tree, then interrogate it:

$ strings /usr/libexec/gcc/x86_64-redhat-linux/4.6.3/cc1 | grep uint128_t
__uint128_t            (or not)
like image 35
crashulator Avatar answered Oct 19 '22 07:10

crashulator


I have not yet dealt with __uint128_t, but based on existing pattern usage, I would expect the following.

#include <stdint.h>

#ifndef UINT128MAX
    #error "__uint128_t not defined"
#endif

Hope this helps

like image 4
Sparky Avatar answered Nov 05 '22 06:11

Sparky


Since the __uint128_t type is a GCC extension, the proper thing to do is probably to check for some known-good version of GCC.

See this page for information about the macros used to version-check the GCC compiler.

like image 3
unwind Avatar answered Nov 05 '22 06:11

unwind