static_assert

static_assert

Defined in header <assert.h>
#define static_assert _Static_assert

This convenience macro expands to the keyword _Static_assert.

Example

#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
}

References

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

See also

C++ documentation for Static Assertion

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/c/error/static_assert

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部