Assertions

Overview

Assertions at preprocessing time are performed via a number of preprocessing directives. Assertions at compile-time can be performed using static_assert.

Runtime Assertions

The assert function, also provided by <assert.h>, is used to perform assertions at runtime. Whether the assertion is performed or not depends on the value of NDEBUG. Generally speaking, release builds should set NDEBUG to 1.

unreachable

Starting in C23, the <stddef.h> header also provides the unreachable macro. This function-like macro indicates the particular flow control that leads to the invocation will never be taken. If reached, the behavior is undefined.

Powered by Forestry.md