我们在编译代码的时候,有时候需要检测某个变量,若不符合我们的要求,则终止编译。
如下参考了optee os中的一个示例的实现:
代码;
COMPILE_TIME_ASSERT(CFG_MMAP_REGIONS >= 13);
代码;
COMPILE_TIME_ASSERT的实现如下:
(optee_os/lib/libutils/isoc/include/assert.h)
#define COMPILE_TIME_ASSERT(x) \
do { \
switch (0) { case 0: case ((x) ? 1: 0): default : break; } \
} while (0)
#endif
263

被折叠的 条评论
为什么被折叠?



