Go to the documentation of this file.
23 #define GCC_MAKE_VERSION(major, minor, patchlevel) ((major) * 10000 + (minor) * 100 + patchlevel)
26 #define GCC_VERSION GCC_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
32 # define CLANG_VERSION GCC_MAKE_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__)
33 #elif defined(__GNUC__)
34 # define CLANG_VERSION 0
41 #define GCC_CHECK_VERSION(major, minor) \
42 (CLANG_VERSION == 0 && \
43 GCC_VERSION >= GCC_MAKE_VERSION(major, minor, 0))
49 #define CLANG_OR_GCC_VERSION(major, minor) \
50 (CLANG_VERSION > 0 || GCC_CHECK_VERSION(major, minor))
56 #define GCC_OLDER_THAN(major, minor) \
57 (GCC_VERSION > 0 && CLANG_VERSION == 0 && \
58 GCC_VERSION < GCC_MAKE_VERSION(major, minor, 0))
61 # if __clang_major__ < 3
62 # error Sorry, your clang version is too old. You need at least version 3.1.
64 #elif defined(__GNUC__)
65 # if GCC_OLDER_THAN(4,9)
66 # error Sorry, your gcc version is too old. You need at least version 4.9.
69 # warning Untested compiler. Use at your own risk!
75 #define CLANG_CHECK_VERSION(major, minor) \
76 (CLANG_VERSION >= GCC_MAKE_VERSION(major, minor, 0))
78 #if CLANG_OR_GCC_VERSION(4,0)
82 #define gcc_const __attribute__((const))
83 #define gcc_deprecated __attribute__((deprecated))
84 #define gcc_may_alias __attribute__((may_alias))
85 #define gcc_malloc __attribute__((malloc))
86 #define gcc_noreturn __attribute__((noreturn))
87 #define gcc_packed __attribute__((packed))
88 #define gcc_printf(a,b) __attribute__((format(printf, a, b)))
89 #define gcc_pure __attribute__((pure))
90 #define gcc_sentinel __attribute__((sentinel))
91 #define gcc_unused __attribute__((unused))
92 #define gcc_warn_unused_result __attribute__((warn_unused_result))
94 #define gcc_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
95 #define gcc_nonnull_all __attribute__((nonnull))
97 #define gcc_likely(x) __builtin_expect (!!(x), 1)
98 #define gcc_unlikely(x) __builtin_expect (!!(x), 0)
100 #define gcc_visibility_hidden __attribute__((visibility("hidden")))
101 #define gcc_visibility_default __attribute__((visibility("default")))
103 #define gcc_always_inline __attribute__((always_inline))
110 #define gcc_deprecated
111 #define gcc_may_alias
115 #define gcc_printf(a,b)
119 #define gcc_warn_unused_result
121 #define gcc_nonnull(...)
122 #define gcc_nonnull_all
124 #define gcc_likely(x) (x)
125 #define gcc_unlikely(x) (x)
127 #define gcc_visibility_hidden
128 #define gcc_visibility_default
130 #define gcc_always_inline inline
134 #if CLANG_OR_GCC_VERSION(4,3)
136 #define gcc_hot __attribute__((hot))
137 #define gcc_cold __attribute__((cold))
146 #if GCC_CHECK_VERSION(4,6)
147 #define gcc_flatten __attribute__((flatten))
154 #define gcc_restrict restrict
155 #elif CLANG_OR_GCC_VERSION(4,0)
157 #define gcc_restrict __restrict__
163 #ifndef __has_feature
165 #define __has_feature(x) 0
168 #if __has_feature(attribute_unused_on_fields)
169 #define gcc_unused_field gcc_unused
171 #define gcc_unused_field
174 #if defined(__GNUC__) || defined(__clang__)
175 #define gcc_unreachable() __builtin_unreachable()
177 #define gcc_unreachable()