You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pe...@apache.org on 2025/11/03 03:49:01 UTC
(celix) 01/04: Add CELIX_HAS_ATTRIBUTE macro to check for attribute support
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/clang-annotations
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 1f2b928e0ede3315f606c6444f8de6f3f0d279a1
Author: PengZheng <ho...@gmail.com>
AuthorDate: Fri Oct 17 14:02:30 2025 +0800
Add CELIX_HAS_ATTRIBUTE macro to check for attribute support
---
libs/utils/include/celix_compiler.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/libs/utils/include/celix_compiler.h b/libs/utils/include/celix_compiler.h
index 3a942f3e0..866a92e94 100644
--- a/libs/utils/include/celix_compiler.h
+++ b/libs/utils/include/celix_compiler.h
@@ -42,6 +42,19 @@ extern "C" {
#define CELIX_UNIQUE_ID(prefix) CELIX_PASTE(CELIX_PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
+/**
+ * A wrapper around `__has_attribute()`, which tests for support for `__attribute__(())`s.
+ *
+ * See also:
+ * clang: https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
+ * gcc: https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
+ */
+#if defined(__has_attribute)
+#define CELIX_HAS_ATTRIBUTE(x) __has_attribute(x)
+#else
+#define CELIX_HAS_ATTRIBUTE(x) 0
+#endif
+
#ifdef __cplusplus
}
#endif