I need to know is there a method for gcc to check presence of those awesome __builtin_MY_DESIRED_FUNCTIONs
For example, I'd like to use __builtin_nan
and be sure it is available for my program and it won't fail during compilation time.
I'll be more specific: on clang there is __has_builtin
"checker" so we can write smth like
#if __has_builtin(__builtin_nan)
But I can't find analog for gcc.
And probably I can rely just on gcc, like "Oh, I'm on gcc now, just let's assume all of those __builtin_
are here like in example below..."
#if __GNUC__
double mynan = __builtin_nan("0");
#endif
And probably it will work, till someone put this "-fno-builtin" compilation flag.
Built-in Function: int __builtin_ffs (int x) Returns one plus the index of the least significant 1-bit of x , or if x is zero, returns zero. Built-in Function: int __builtin_clz (unsigned int x) Returns the number of leading 0-bits in x , starting at the most significant bit position.
You can use the __builtin_expect built-in function to indicate that an expression is likely to evaluate to a specified value. The compiler can use this knowledge to direct optimizations. This built-in function is portable with the GNU C/C++ __builtin_expect function.
GCC allows the declaration of nested functions (a function defined inside another function). The nested function's name will be local to the block where it is defined and can access all the variables of the containing function that are visible at the point of its definition.
The identifier __PRETTY_FUNCTION__ holds the name of the function pretty printed in a language specific fashion. These names are always the same in a C function, but in a C++ function they may be different. For example, this program: extern "C" { extern int printf (char *, ...
Good news! a __has_builtin
was added in GCC 10 (see change notes):
The special operator __has_builtin (operand) may be used in constant integer contexts and in preprocessor ‘#if’ and ‘#elif’ expressions to test whether the symbol named by its operand is recognized as a built-in function by GCC in the current language and conformance mode. It evaluates to a constant integer with a nonzero value if the argument refers to such a function, and to zero otherwise. The operator may also be used in preprocessor ‘#if’ and ‘#elif’ expressions. The __has_builtin operator by itself, without any operand or parentheses, acts as a predefined macro so that support for it can be tested in portable code. Thus, the recommended use of the operator is as follows:
#if defined __has_builtin
# if __has_builtin (__builtin_object_size)
# define builtin_object_size(ptr) __builtin_object_size (ptr, 2)
# endif
#endif
#ifndef builtin_object_size
# define builtin_object_size(ptr) ((size_t)-1)
#endif
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