opr: Add opr_StaticAssert 92/11792/5
authorAndrew Deason <adeason@sinenomine.net>
Fri, 13 Feb 2015 19:11:09 +0000 (13:11 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 15 Sep 2016 01:54:59 +0000 (21:54 -0400)
Add a static assert macro, for asserting that certain build-time
expressions are true.

Change-Id: I33b0e7168f041e8e8406710d05689e044af45fad
Reviewed-on: https://gerrit.openafs.org/11792
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/opr/opr.h

index a6aaaf2..5891a70 100644 (file)
@@ -54,6 +54,13 @@ extern void opr_AssertFailU(const char *, const char *, int) AFS_NORETURN;
 # define opr_Verify(ex) __opr_Verify(ex)
 #endif
 
+/* opr_StaticAssert is a static build-time assertion, to assert certain
+ * static values (such as sizeof results). If the assertion fails, the
+ * build will fail. */
+
+#define opr_StaticAssert(ex) \
+    ((void)(sizeof(char[1 - 2 * !(ex)])))
+
 /* casestrcpy.c */
 #define lcstring opr_lcstring
 #define ucstring opr_ucstring