summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-10-17 19:59:53 +0200
committerThomas Haller <thaller@redhat.com>2017-10-17 20:02:59 +0200
commitacbab884ee80d8816169892340dba995f23b90bc (patch)
tree6be6f0b9e7c93a19ca8c69b4800412b7cab993ba
parentbdb8e65434e1556f0022c2f1fc5a1427e36b0976 (diff)
downloadNetworkManager-acbab884ee80d8816169892340dba995f23b90bc.tar.gz
shared: add _NM_ENSURE_TYPE() macro
-rw-r--r--shared/nm-utils/nm-macros-internal.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index 352e581365..bbdf50be71 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -288,6 +288,18 @@ NM_G_ERROR_MSG (GError *error)
((type *) (obj))
#endif
+#if _NM_CC_SUPPORT_GENERIC
+/* returns @value, if the type of @value matches @type.
+ * This requires support for C11 _Generic(). If no support is
+ * present, this returns @value directly.
+ *
+ * It's useful to check the let the compiler ensure that @value is
+ * of a certain type. */
+#define _NM_ENSURE_TYPE(type, value) (_Generic ((value), type: (value)))
+#else
+#define _NM_ENSURE_TYPE(type, value) (value)
+#endif
+
/*****************************************************************************/
#define _NM_IN_SET_EVAL_1( op, _x, y) (_x == (y))