static_assert()

Display a diagnostic message at compile time

Synopsis:

#include <assert.h>

#define static_assert _Static_assert

Description:

The static_assert() macro expands to the C11 _Static_assert() macro, which performs a compile-time check:

_Static_assert( expression, message )

The expression is evaluated at compile time; if it's zero, a compile-time error occurs, and the compiler displays message as part of the error message. If the value of expression is nonzero, nothing happens.

Examples:

#include <assert.h>

int main(void)
{
    static_assert(sizeof(int) < sizeof(char),
      "This program requires that an int be smaller than a char.");
}

If you compile this program, the output will look something like this:

$ qcc -o s_assert s_assert.c 
In file included from s_assert.c:1:0:
s_assert.c: In function 'main':
s_assert.c:5:5: error: static assertion failed: "This program requires that an int be smaller than a char."
     static_assert(sizeof(int) < sizeof(char),
     ^

Classification:

C11