]> The Tcpdump Group git mirrors - libpcap/blobdiff - pcap/compiler-tests.h
Handle older OSes without DLT_PRISM_HEADER/DLT_AIRONET_HEADER/DLT_PPI.
[libpcap] / pcap / compiler-tests.h
index 205cd7a610bd4a6ef137138ad917102c6cc79e0b..ea5962c7bf5e6849521167db95274ec81f06576b 100644 (file)
@@ -35,7 +35,6 @@
 #ifndef lib_pcap_compiler_tests_h
 #define lib_pcap_compiler_tests_h
 
-
 /*
  * This was introduced by Clang:
  *
   #define __has_attribute(x) 0
 #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 Clang major.minor or a later release.
+ */
+
+#if !defined(__clang__)
+#define PCAP_IS_AT_LEAST_CLANG_VERSION(major, minor) 0
+#else
+#define PCAP_IS_AT_LEAST_CLANG_VERSION(major, minor) \
+       (__clang_major__ > (major) || \
+        (__clang_major__ == (major) && __clang_minor__ >= (minor)))
+#endif
+
+/*
+ * 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
  * 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
  * (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)))
 
-#endif /* lib_pcap_funcattrs_h */
+#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_compiler_tests_h */