目录
宏定义
COMPILE_TIME_ASSERT
源码
#define COMPILE_TIME_ASSERT(e) \
do { \
switch (0) { case 1:case !(e):break; } \
} while (0)
用法
COMPILE_TIME_ASSERT(CFG_MMAP_REGIONS >= 13);
说明
- 参数表达式为真,编译通过
- 参数表达式不为真,编译会由于程序中存在相同 case 值而报错退出
举例
# gcc main.c -o main
main.c: In function ‘main’:
main.c:5:29: error: duplicate case value
5 | switch (0) { case 1:case !(e):break; } \
| ^~~~