C语言中compile time assert的实现
生活随笔
收集整理的這篇文章主要介紹了
C语言中compile time assert的实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我們在編譯代碼的時候,有時候需要檢測某個變量,若不符合我們的要求,則終止編譯。
如下參考了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總結
以上是生活随笔為你收集整理的C语言中compile time assert的实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: optee3.14中MMU页表查询的所需
- 下一篇: 在enable mmu之前可以使用mmu