static_assert

来自cppreference.com
< c‎ | error
定义于头文件 <assert.h>
#define static_assert _Static_assert

此便利宏展开成关键词 _Static_assert

示例

#include <assert.h>
int main(void)
{
    static_assert(2 + 2 == 4, "2+2 isn't 4");      // 良式
    static_assert(sizeof(int) < sizeof(char),
                 "this program requires that int is less than char"); // 编译时错误
}

引用

  • C11 标准(ISO/IEC 9899:2011):
  • 7.2/3 Diagnostics <assert.h> (p: 186)

参阅