I am not sure if there is a version of BUG_ON() for compile time
asserts. Basically, if we have an infrastructure of the form
/*
* From C/C++ users journal November 2004
*/
#define STATIC_BUG_ON(e) \
switch (0) { \
case 0: \
case (e): \
; \
}
Then the STATIC_BUG_ON() can catch as shown below.
#define TASK_COMM_LEN 16
#define T_COMM_LEN 20
int
main(void)
{
STATIC_BUG_ON(TASK_COMM_LEN == T_COMM_LEN);
}
STATIC_BUG_ON gives the following warning
bug_on_c.c: In function `main':
bug_on_c.c:19: duplicate case value
bug_on_c.c:19: previously used here
but with T_COMM_LEN set to 16
It compiles without any errors, the code generated also
looks like it has no overhead
int
main(void)
{
8048310: 55 push %ebp
8048311: 89 e5 mov %esp,%ebp
8048313: 83 ec 08 sub $0x8,%esp
8048316: 83 e4 f0 and $0xfffffff0,%esp
STATIC_BUG_ON(TASK_COMM_LEN == T_COMM_LEN);
}
8048319: c9 leave
804831a: c3 ret
804831b: 90 nop
Assuming such infrastructure is available, you could then
do
#ifdef __KERNEL__
#include <linux/sched.h>
#define TS_COMM_LEN 16
STATIC_BUG_ON (TS_COMM_LEN == TASK_COMM_LEN);
#endif
Comments?