?
This document uses PHP Chinese website manual Release
_Static_assert ( expression , message ) | (since C11) |
---|
expression | - | any integer constant expression |
---|---|---|
message | - | any string literal |
此關鍵字也可用作方便宏static_assert
,可在標題中找到<assert.h>
。
常量表達式在編譯時進行評估并與零進行比較。如果它比較等于零,則會發(fā)生編譯時錯誤,編譯器必須顯示消息作為錯誤消息的一部分(不需要顯示不在基本源字符集中的字符)。
否則,如果表達式不等于零,則什么都不會發(fā)生; 沒有代碼被發(fā)射。
_Static_assert
.
#include <assert.h>int main(void){ // Test if math works. static_assert(2 + 2 == 4, "Whoa dude!"); // or _Static_assert(... // This will produce an error at compile time. static_assert(sizeof(int) < sizeof(char), "this program requires that int is less than char");}