diff options
| -rw-r--r-- | include/c.h | 33 | ||||
| -rw-r--r-- | include/xxhash.h | 35 |
2 files changed, 36 insertions, 32 deletions
diff --git a/include/c.h b/include/c.h index dcb2d683c7..e0148e019c 100644 --- a/include/c.h +++ b/include/c.h @@ -82,6 +82,39 @@ # endif #endif +#ifdef __has_attribute +# define UL_HAS_ATTRIBUTE(x) __has_attribute(x) +#else +# define UL_HAS_ATTRIBUTE(x) 0 +#endif + +/* C-language Attributes are added in C23. */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute) +# define UL_HAS_C_ATTRIBUTE(x) __has_c_attribute(x) +#else +# define UL_HAS_C_ATTRIBUTE(x) 0 +#endif + +#if defined(__cplusplus) && defined(__has_cpp_attribute) +# define UL_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) +#else +# define UL_HAS_CPP_ATTRIBUTE(x) 0 +#endif + +/* +Define FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute +introduced in CPP17 and C23. +CPP17 : https://en.cppreference.com/w/cpp/language/attributes/fallthrough +C23 : https://en.cppreference.com/w/c/language/attributes/fallthrough +*/ +#if UL_HAS_C_ATTRIBUTE(fallthrough) || UL_HAS_CPP_ATTRIBUTE(fallthrough) +# define FALLTHROUGH [[fallthrough]] +#elif UL_HAS_ATTRIBUTE(__fallthrough__) +# define FALLTHROUGH __attribute__ ((__fallthrough__)) +#else +# define FALLTHROUGH /* fallthrough */ +#endif + /* * It evaluates to 1 if the attribute/feature is supported by the current diff --git a/include/xxhash.h b/include/xxhash.h index c17521f99f..5a581b8884 100644 --- a/include/xxhash.h +++ b/include/xxhash.h @@ -605,39 +605,10 @@ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t */ XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src); +/* Reuse FALLTHROUGH macro from c.h */ +#include "c.h" -#ifdef __has_attribute -# define XXH_HAS_ATTRIBUTE(x) __has_attribute(x) -#else -# define XXH_HAS_ATTRIBUTE(x) 0 -#endif - -/* C-language Attributes are added in C23. */ -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute) -# define XXH_HAS_C_ATTRIBUTE(x) __has_c_attribute(x) -#else -# define XXH_HAS_C_ATTRIBUTE(x) 0 -#endif - -#if defined(__cplusplus) && defined(__has_cpp_attribute) -# define XXH_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) -#else -# define XXH_HAS_CPP_ATTRIBUTE(x) 0 -#endif - -/* -Define XXH_FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute -introduced in CPP17 and C23. -CPP17 : https://en.cppreference.com/w/cpp/language/attributes/fallthrough -C23 : https://en.cppreference.com/w/c/language/attributes/fallthrough -*/ -#if XXH_HAS_C_ATTRIBUTE(fallthrough) || XXH_HAS_CPP_ATTRIBUTE(fallthrough) -# define XXH_FALLTHROUGH [[fallthrough]] -#elif XXH_HAS_ATTRIBUTE(__fallthrough__) -# define XXH_FALLTHROUGH __attribute__ ((__fallthrough__)) -#else -# define XXH_FALLTHROUGH /* fallthrough */ -#endif +#define XXH_FALLTHROUGH FALLTHROUGH /*! * @} |
