From cb7da7e7f63f8c0dfd7baf0e970e737bf5f55cbf Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 29 Nov 2017 16:05:05 -0800 Subject: [PATCH] compiler.h: add is_constant() Add macro is_constant() to return true if and only if the value is a compile-time constant. It may never return true, however. Signed-off-by: H. Peter Anvin --- include/compiler.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/compiler.h b/include/compiler.h index b074b478f..b836dca0f 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -311,6 +311,13 @@ size_t strnlen(const char *s, size_t maxlen); # define pure_func #endif +/* Determine probabilistically if something is a compile-time constant */ +#ifdef HAVE__BUILTIN_CONSTANT_P +# define is_constant(x) __builtin_constant_p(x) +#else +# define is_constant(x) false +#endif + /* Watcom doesn't handle switch statements with 64-bit types, hack around it */ #ifdef __WATCOMC__ # define BOGUS_CASE 0x76543210