LATER... ei_kerberos_kdc_session_key ...
[wireshark-sm.git] / include / ws_compiler_tests.h
blob4b686734a26f91c8cc3d99855301913bcd71e496
1 /* ws_compiler_tests.h
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #ifndef __WS_COMPILER_TESTS_H__
11 #define __WS_COMPILER_TESTS_H__
14 * This was introduced by Clang:
16 * http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
18 * in some version (which version?); it has been picked up by GCC 5.0.
20 #ifndef __has_attribute
22 * It's a macro, so you can check whether it's defined to check
23 * whether it's supported.
25 * If it's not, define it to always return 0, so that we move on to
26 * the fallback checks.
28 #define __has_attribute(x) 0
29 #endif
32 * Note that the C90 spec's "6.8.1 Conditional inclusion" and the
33 * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say:
35 * Prior to evaluation, macro invocations in the list of preprocessing
36 * tokens that will become the controlling constant expression are
37 * replaced (except for those macro names modified by the defined unary
38 * operator), just as in normal text. If the token "defined" is
39 * generated as a result of this replacement process or use of the
40 * "defined" unary operator does not match one of the two specified
41 * forms prior to macro replacement, the behavior is undefined.
43 * so you shouldn't use defined() in a #define that's used in #if or
44 * #elif. Some versions of Clang, for example, will warn about this.
46 * Instead, we check whether the pre-defined macros for particular
47 * compilers are defined and, if not, define the "is this version XXX
48 * or a later version of this compiler" macros as 0.
52 * Check whether this is GCC major.minor or a later release, or some
53 * compiler that claims to be "just like GCC" of that version or a
54 * later release.
57 #if !defined(__GNUC__)
58 #define WS_IS_AT_LEAST_GNUC_VERSION(major, minor) 0
59 #else
60 #define WS_IS_AT_LEAST_GNUC_VERSION(major, minor) \
61 (__GNUC__ > (major) || \
62 (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
63 #endif
66 * Check if the compiler is GCC and not a compiler from another
67 * vendor that also defines __GNUC__ (claiming support for GNU C dialect).
68 * Unfortunately there is no way to test this directly so we need
69 * to exclude other known compilers that claim such support (hacky).
71 #if defined(__GNUC__) && \
72 !defined(__clang__) && \
73 !defined(__INTEL_COMPILER) && \
74 !defined(__INTEL_LLVM_COMPILER)
75 #define WS_GCC_VERSION \
76 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
77 #endif
80 * Check whether this is Clang major.minor or a later release.
83 #if !defined(__clang__)
84 #define WS_IS_AT_LEAST_CLANG_VERSION(major, minor) 0
85 #else
86 #define WS_IS_AT_LEAST_CLANG_VERSION(major, minor) \
87 (__clang_major__ > (major) || \
88 (__clang_major__ == (major) && __clang_minor__ >= (minor)))
89 #endif
92 * Check whether this is Sun C/SunPro C/Oracle Studio major.minor
93 * or a later release.
95 * The version number in __SUNPRO_C is encoded in hex BCD, with the
96 * uppermost hex digit being the major version number, the next
97 * one or two hex digits being the minor version number, and
98 * the last digit being the patch version.
100 * It represents the *compiler* version, not the product version;
101 * see
103 * https://sourceforge.net/p/predef/wiki/Compilers/
105 * for a partial mapping, which we assume continues for later
106 * 12.x product releases.
109 #if !defined(__SUNPRO_C)
110 #define WS_IS_AT_LEAST_SUNC_VERSION(major, minor) 0
111 #else
112 #define WS_SUNPRO_VERSION_TO_BCD(major, minor) \
113 (((minor) >= 10) ? \
114 (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \
115 (((major) << 8) | ((minor) << 4)))
116 #define WS_IS_AT_LEAST_SUNC_VERSION(major, minor) \
117 (__SUNPRO_C >= WS_SUNPRO_VERSION_TO_BCD((major), (minor)))
118 #endif
121 * Check whether this is IBM XL C major.minor or a later release.
123 * The version number in __xlC__ has the major version in the
124 * upper 8 bits and the minor version in the lower 8 bits.
127 #if !defined(__xlC__)
128 #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) 0
129 #else
130 #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) \
131 (__xlC__ >= (((major) << 8) | (minor)))
132 #endif
135 * Check whether this is HP aC++/HP C major.minor or a later release.
137 * The version number in __HP_aCC is encoded in zero-padded decimal BCD,
138 * with the "A." stripped off, the uppermost two decimal digits being
139 * the major version number, the next two decimal digits being the minor
140 * version number, and the last two decimal digits being the patch version.
141 * (Strip off the A., remove the . between the major and minor version
142 * number, and add two digits of patch.)
145 #if !defined(__HP_aCC)
146 #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) 0
147 #else
148 #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) \
149 (__HP_aCC >= ((major)*10000 + (minor)*100))
150 #endif
152 #endif /* __WS_COMPILER_TESTS_H__ */