Static assertions (C11)
RoyHu 270003S1XN Visits (1263)
IBM XL C/C++ support the static assertion feature starting from V12.1. You can declare assertions to detect and diagnose common usage errors at compile time. To enable this feature, specify the -qlanglvl=extc1x option.
A static assertion can be declared using the _Static_assert keyword with the syntax as follows:
_Static_assert declaration syntax
The constant_expression must be an integer constant expression. If the integer constant expression evaluates to 0, the compiler issues a severe error containing the string literal with the source location of the _Static_assert declaration. Otherwise, the _Static_assert declaration has no effect.
The declaration of static assertions does not declare a new type or object, and does not imply any size or time cost at run time.
The addition of static assertions to the C language has the following benefits:
You can declare static assertions to check important program invariants at compile time.
The following example shows the use of a _Static_assert declaration inside a structure.
struct B b;
For details about the static assertions, see the following topic:
For details about the -qlanglvl=extc1x option, see the following topic: