diff options
Diffstat (limited to 'pcap/compiler-tests.h')
-rw-r--r-- | pcap/compiler-tests.h | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/pcap/compiler-tests.h b/pcap/compiler-tests.h index 205cd7a6..8876c67c 100644 --- a/pcap/compiler-tests.h +++ b/pcap/compiler-tests.h @@ -55,17 +55,41 @@ #endif /* + * Note that the C90 spec's "6.8.1 Conditional inclusion" and the + * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say: + * + * Prior to evaluation, macro invocations in the list of preprocessing + * tokens that will become the controlling constant expression are + * replaced (except for those macro names modified by the defined unary + * operator), just as in normal text. If the token "defined" is + * generated as a result of this replacement process or use of the + * "defined" unary operator does not match one of the two specified + * forms prior to macro replacement, the behavior is undefined. + * + * so you shouldn't use defined() in a #define that's used in #if or + * #elif. Some versions of Clang, for example, will warn about this. + * + * Instead, we check whether the pre-defined macros for particular + * compilers are defined and, if not, define the "is this version XXX + * or a later version of this compiler" macros as 0. + */ + +/* * Check whether this is GCC major.minor or a later release, or some * compiler that claims to be "just like GCC" of that version or a * later release. */ + +#if ! defined(__GNUC__) +#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) 0 +#else #define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \ - (defined(__GNUC__) && \ - (__GNUC__ > (major) || \ - (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))) + (__GNUC__ > (major) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) +#endif /* - * Check wehether this is Sun C/SunPro C/Oracle Studio major.minor + * Check whether this is Sun C/SunPro C/Oracle Studio major.minor * or a later release. * * The version number in __SUNPRO_C is encoded in hex BCD, with the @@ -81,26 +105,34 @@ * for a partial mapping, which we assume continues for later * 12.x product releases. */ + +#if ! defined(__SUNPRO_C) +#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) 0 +#else #define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \ (((minor) >= 10) ? \ (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \ (((major) << 8) | ((minor) << 4))) -#define PCAP_IS_AT_LEAST_SUNC_VERSION(major, minor) \ - (defined(__SUNPRO_C) && \ - (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor)))) +#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) \ + (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor))) +#endif /* - * Check wehether this is IBM XL C major.minor or a later release. + * Check whether this is IBM XL C major.minor or a later release. * * The version number in __xlC__ has the major version in the * upper 8 bits and the minor version in the lower 8 bits. */ + +#if ! defined(__xlC__) +#define PCAP_IS_AT_LEAST_XL_C_VERSION(major,minor) 0 +#else #define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \ - (defined(__xlC__) && __xlC__ >= (((major) << 8) | (minor))) + (__xlC__ >= (((major) << 8) | (minor))) +#endif /* - * Check wehether this is Sun C/SunPro C/Oracle Studio major.minor - * or a later release. + * Check whether this is HP aC++/HP C major.minor or a later release. * * The version number in __HP_aCC is encoded in zero-padded decimal BCD, * with the "A." stripped off, the uppermost two decimal digits being @@ -109,8 +141,12 @@ * (Strip off the A., remove the . between the major and minor version * number, and add two digits of patch.) */ -#define PCAP_IS_AT_LEAST_HP_C_VERSION(major, minor) \ - (defined(__HP_aCC) && \ - (__HP_aCC >= ((major)*10000 + (minor)*100))) + +#if ! defined(__HP_aCC) +#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) 0 +#else +#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) \ + (__HP_aCC >= ((major)*10000 + (minor)*100)) +#endif #endif /* lib_pcap_funcattrs_h */ |