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
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
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
57 #if !defined(__GNUC__)
58 #define WS_IS_AT_LEAST_GNUC_VERSION(major, minor) 0
60 #define WS_IS_AT_LEAST_GNUC_VERSION(major, minor) \
61 (__GNUC__ > (major) || \
62 (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
66 * Check whether this is Clang major.minor or a later release.
69 #if !defined(__clang__)
70 #define WS_IS_AT_LEAST_CLANG_VERSION(major, minor) 0
72 #define WS_IS_AT_LEAST_CLANG_VERSION(major, minor) \
73 (__clang_major__ > (major) || \
74 (__clang_major__ == (major) && __clang_minor__ >= (minor)))
78 * Check whether this is Sun C/SunPro C/Oracle Studio major.minor
81 * The version number in __SUNPRO_C is encoded in hex BCD, with the
82 * uppermost hex digit being the major version number, the next
83 * one or two hex digits being the minor version number, and
84 * the last digit being the patch version.
86 * It represents the *compiler* version, not the product version;
89 * https://sourceforge.net/p/predef/wiki/Compilers/
91 * for a partial mapping, which we assume continues for later
92 * 12.x product releases.
95 #if !defined(__SUNPRO_C)
96 #define WS_IS_AT_LEAST_SUNC_VERSION(major, minor) 0
98 #define WS_SUNPRO_VERSION_TO_BCD(major, minor) \
100 (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \
101 (((major) << 8) | ((minor) << 4)))
102 #define WS_IS_AT_LEAST_SUNC_VERSION(major, minor) \
103 (__SUNPRO_C >= WS_SUNPRO_VERSION_TO_BCD((major), (minor)))
107 * Check whether this is IBM XL C major.minor or a later release.
109 * The version number in __xlC__ has the major version in the
110 * upper 8 bits and the minor version in the lower 8 bits.
113 #if !defined(__xlC__)
114 #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) 0
116 #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) \
117 (__xlC__ >= (((major) << 8) | (minor)))
121 * Check whether this is HP aC++/HP C major.minor or a later release.
123 * The version number in __HP_aCC is encoded in zero-padded decimal BCD,
124 * with the "A." stripped off, the uppermost two decimal digits being
125 * the major version number, the next two decimal digits being the minor
126 * version number, and the last two decimal digits being the patch version.
127 * (Strip off the A., remove the . between the major and minor version
128 * number, and add two digits of patch.)
131 #if !defined(__HP_aCC)
132 #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) 0
134 #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) \
135 (__HP_aCC >= ((major)*10000 + (minor)*100))
138 #endif /* __WS_COMPILER_TESTS_H__ */