P99

◆ static_assert

#define static_assert (   EXPR,
  DIAGSTR 
)
Value:
extern char const p00_compiletime_assert[ \
sizeof((void const*[3*(!!(EXPR)) - 1]){ \
&p00_compiletime_assert, \
"static assertion failed: " P99_STRINGIFY(EXPR) ", " DIAGSTR}) \
]

Evaluate expression EXPR at compile time and ensure that it is fulfilled.

The expression must be given as the first argument. The second argument is a diagnostic string that should be part of the diagnostic message when the assertion fails.

Not all compilers give a useful message when an assertion is not fulfilled, but all should give at least the line number and stop compilation.

Remarks
This functionality will be directly supported in C11 and the macro static_assert must be provided by assert.h, which we include.

Definition at line 695 of file p99_compiler.h.

P99_STRINGIFY
#define P99_STRINGIFY(...)
Transform the argument list into one string.
Definition: p99_compiler.h:109