checkAPIs.pl: improve value_string validation in field definitions
[metze/wireshark/wip.git] / ws_compiler_tests.h
1 /* ws_compiler_tests.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #ifndef __WS_COMPILER_TESTS_H__
11 #define __WS_COMPILER_TESTS_H__
12
13 /*
14  * This was introduced by Clang:
15  *
16  *     http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
17  *
18  * in some version (which version?); it has been picked up by GCC 5.0.
19  */
20 #ifndef __has_attribute
21   /*
22    * It's a macro, so you can check whether it's defined to check
23    * whether it's supported.
24    *
25    * If it's not, define it to always return 0, so that we move on to
26    * the fallback checks.
27    */
28   #define __has_attribute(x) 0
29 #endif
30
31 /*
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:
34  *
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.
42  *
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.
45  *
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.
49  */
50
51 /*
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.
55  */
56
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
64
65 /*
66  * Check whether this is Clang major.minor or a later release.
67  */
68
69 #if !defined(__clang__)
70   #define WS_IS_AT_LEAST_CLANG_VERSION(major, minor) 0
71 #else
72   #define WS_IS_AT_LEAST_CLANG_VERSION(major, minor) \
73         (__clang_major__ > (major) || \
74          (__clang_major__ == (major) && __clang_minor__ >= (minor)))
75 #endif
76
77 /*
78  * Check whether this is Sun C/SunPro C/Oracle Studio major.minor
79  * or a later release.
80  *
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.
85  *
86  * It represents the *compiler* version, not the product version;
87  * see
88  *
89  *    https://sourceforge.net/p/predef/wiki/Compilers/
90  *
91  * for a partial mapping, which we assume continues for later
92  * 12.x product releases.
93  */
94
95 #if !defined(__SUNPRO_C)
96   #define WS_IS_AT_LEAST_SUNC_VERSION(major, minor) 0
97 #else
98   #define WS_SUNPRO_VERSION_TO_BCD(major, minor) \
99         (((minor) >= 10) ? \
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)))
104 #endif
105
106 /*
107  * Check whether this is IBM XL C major.minor or a later release.
108  *
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.
111  */
112
113 #if !defined(__xlC__)
114   #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) 0
115 #else
116   #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) \
117         (__xlC__ >= (((major) << 8) | (minor)))
118 #endif
119
120 /*
121  * Check whether this is HP aC++/HP C major.minor or a later release.
122  *
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.)
129  */
130
131 #if !defined(__HP_aCC)
132   #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) 0
133 #else
134   #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) \
135         (__HP_aCC >= ((major)*10000 + (minor)*100))
136 #endif
137
138 #endif /* __WS_COMPILER_TESTS_H__ */