Skip to content

Commit 5535578

Browse files
committed
Add a static assert macro
Add a static assert macro that evaluates to a struct definition, so we can assert things statically. This is useful vs STATIC_ASSERT_EXPR, which evaluates to an expression, where an expression is not needed.
1 parent 0ec1d05 commit 5535578

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

library/include/utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@
3434
#define STATIC_ASSERT_EXPR( const_expr ) \
3535
( 0 && sizeof( struct { int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) )
3636

37+
/* A statement that does nothing after its built. If `const_expr` is not a
38+
* compile-time constant with a nonzero value, cause a compile-time error. */
39+
#define STATIC_ASSERT( const_expr, msg ) \
40+
struct STATIC_ASSERT##msg { \
41+
int STATIC_ASSERT_##msg : 1 - 2 * ! ( const_expr ); \
42+
}
43+
3744
#endif /* MC_UTILS_H */

0 commit comments

Comments
 (0)