Names specified here
Name Description Notes Source Availability
_Static_assert Static assertion L + Keyword C11
Names specified for <assert.h>, “Diagnostic assertions”
Name Description Notes Source Availability
assert() Test assertion M (·) <assert.h> C89 C90 C95 C99 C11
NDEBUG Disable assertion-based debugging ? M User-defined C89 C90 C95 C99 C11
static_assert Static assertion M + <assert.h> C11

This header is available in C89, C90, C95, C99 and C11.

Assertions are conditions that the programmer believes should always be true. If an assertion is found to be false, it causes a running program to fail, and may prevent the program from even starting (usually during compilation, for example). This helps debugging by ensuring that errors in the programmer's understanding of a program's behaviour are detected before they manifest a more obscure problem during tests.

#include <assert.h>

void assert(scalar expr);

The header <assert.h> provides a macro assert for expressing run-time assertions. When an assertion is executed, its condition is evaluated. If found to be false, the program is aborted, with a message that may give the condition that failed, and the line number where it is asserted. For example:

assert(i == 0);

If NDEBUG is defined before including <assert.h>, the effects of the assert macro are disabled.

From C11, you can declare static assertions based on constant expressions that should be true even before the program starts running. For example:

_Static_assert(sizeof(char) == 1, "Not C!");

This allows a program to be rejected before it is executed.

the following is also defined:

#include <assert.h>

#define static_assert _Static_assert

So, you can write it like this:

#include <assert.h>

static_assert(sizeof(char) == 1, "Not C!");
static_assert-declaration
_Static_assert ( constant-expression , string-literal ) ;

CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2023-10-04T20:24:03.201+0000