[glib] macros: add G_GNUC_CHECK_VERSION() for compiler checks.



commit 3272267b99670e1bfccf5aebe97ead5e6f8b1bab
Author: Christian Hergert <christian hergert me>
Date:   Sun Apr 13 17:17:59 2014 -0700

    macros: add G_GNUC_CHECK_VERSION() for compiler checks.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728099

 docs/reference/glib/glib-sections.txt |    1 +
 glib/docs.c                           |   15 +++++++++++++++
 glib/gmacros.h                        |    6 ++++++
 3 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index aec585e..4dbdd06 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -407,6 +407,7 @@ G_STATIC_ASSERT
 G_STATIC_ASSERT_EXPR
 
 <SUBSECTION>
+G_GNUC_CHECK_VERSION
 G_GNUC_EXTENSION
 G_GNUC_CONST
 G_GNUC_PURE
diff --git a/glib/docs.c b/glib/docs.c
index 16a608c..875504a 100644
--- a/glib/docs.c
+++ b/glib/docs.c
@@ -1996,6 +1996,21 @@
  */
 
 /**
+ * G_GNUC_CHECK_VERSION:
+ *
+ * Expands to a a check for a compiler with __GNUC__ defined and a version
+ * greater than or equal to the major and minor numbers provided. For example,
+ * the following would only match on compilers such as GCC 4.8 or newer.
+ *
+ * |[<!-- language="C" -->
+ * #if G_GNUC_CHECK_VERSION(4, 8)
+ * #endif
+ * ]|
+ *
+ * Since: 2.42
+ */
+
+/**
  * G_GNUC_CONST:
  *
  * Expands to the GNU C const function attribute if the compiler is gcc.
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 55af81f..9b057ce 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -37,6 +37,12 @@
  */
 #include <stddef.h>
 
+#define G_GNUC_CHECK_VERSION(major, minor) \
+    (defined(__GNUC__) && \
+     ((__GNUC__ > (major)) || \
+      ((__GNUC__ == (major)) && \
+       (__GNUC_MINOR__ >= (minor)))))
+
 /* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
  * where this is valid. This allows for warningless compilation of
  * "long long" types even in the presence of '-ansi -pedantic'. 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]