OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
Compile time assert macro

From: Stefan Fritsch (sfsfritsch.de)
Date: Fri May 03 2013 - 02:35:26 CDT


Hi,

I think a CTASSERT macro like in FreeBSD would be nice. It could be used
to verify assumptions about type and struct sizes.

This should work on gcc 2.9.5, too, but I haven't tested it.

--- sys/lib/libkern/libkern.h
+++ sys/lib/libkern/libkern.h
-138,6 +138,9 abs(int j)
 #endif
 #endif
 
+#define CTASSERT(x) extern char _ctassert[(x) ? 1 : -1 ] \
+ __attribute__((__unused__))
+
 /* Prototypes for non-quad routines. */
 void __assert(const char *, const char *, int, const char *)
             __attribute__ ((__noreturn__));