aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils/utils.h
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2014-07-04 14:35:27 +0200
committerMartin Willi <martin@revosec.ch>2014-08-25 09:48:53 +0200
commitbb6be261974788d971226d7508bcbc49af86e96e (patch)
tree9630c61844572f80dceffb2c705d86fc2f540f22 /src/libstrongswan/utils/utils.h
parent8986e2da47ec6e5a57483a1034d3332f8fdd2533 (diff)
downloadstrongswan-bb6be261974788d971226d7508bcbc49af86e96e.tar.bz2
strongswan-bb6be261974788d971226d7508bcbc49af86e96e.tar.xz
utils: Add some initial build time assertion macros
These are useful to assert constants during build time. We evaluate the expression to 0 when valid, so we can safely use the evaluated value.
Diffstat (limited to 'src/libstrongswan/utils/utils.h')
-rw-r--r--src/libstrongswan/utils/utils.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/utils.h b/src/libstrongswan/utils/utils.h
index 1b822dd61..cb60c6e3e 100644
--- a/src/libstrongswan/utils/utils.h
+++ b/src/libstrongswan/utils/utils.h
@@ -60,6 +60,20 @@
#define BUF_LEN 512
/**
+ * Build assertion macro for integer expressions, evaluates to 0
+ */
+#define BUILD_ASSERT(x) (sizeof(char[(x) ? 0 : -1]))
+
+/**
+ * Build time check to assert a is an array, evaluates to 0
+ *
+ * The address of an array element has a pointer type, which is not compatible
+ * to the array type.
+ */
+#define BUILD_ASSERT_ARRAY(a) \
+ BUILD_ASSERT(!__builtin_types_compatible_p(typeof(a), typeof(&(a)[0])))
+
+/**
* General purpose boolean type.
*/
#ifdef HAVE_STDBOOL_H