Interface __is_constant

Preprocessor macro expanding to an expression

#include <SYS/TYPES.H>

if (__is_constant(expression)) ...

Description

This macro expands to a compiler-specific function that is evaluated at compile-time and that tells if the expression is constant.

It may be used for alternate code paths in inline functions, that will be generated for constant or non-constant arguments. Because __is_constant is always evaluated at compile-time, one of the branches of the if statement will always be removed by the optimizer.

The caller should not depend on the ability of a compiler to return this information. This macro should be used only for optimization purposes.

Arguments

Returns

This macro returns non-zero if the compiler can prove that the expression is constant. If it can't prove it (either because the expression is too complex or if optimizations are turned off), it returns 0. It also returns 0 if the compiler doesn't support this functionality.

Implementation note

On gcc compiler, this macro expands to __builtin_constant_p(expression + expression) function. Summing two expressions is required as a workaround against a bug.

See also

__likely, __unlikely