首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

static_assert

在头文件<assert.h>中定义

?

?

#define static_assert _Static_assert

?

?

此便利宏扩展为关键字_Static_assert。

代码语言:javascript
复制
#include <assert.h>
int main(void)
{
    static_assert(2 + 2 == 4, "2+2 isn't 4");      // well-formed
    static_assert(sizeof(int) < sizeof(char),
                 "this program requires that int is less than char"); // compile-time error
}

参考

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

另请参阅

| 静态声明的C ++文档

|:----|

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com