#
The header <cassert> provides a macro for documenting C++ program assertions and a mechanism for disabling the assertion checks through defining the macro NDEBUG.

19.3.2 Header <cassert> synopsis [cassert.syn]

#define assert(.) see below

19.3.3 The assert macro [assertions.assert]

1
#
If NDEBUG is defined as a macro name at the point in the source file where <cassert> is included, the assert macro is defined as #define assert(.) ((void)0)
Otherwise, the assert macro puts a diagnostic test into programs; it expands to an expression of type void which has the following effects:
  • __VA_ARGS__ is evaluated and contextually converted to bool.
  • If the evaluation yields true there are no further effects.
  • Otherwise, the assert macro's expression creates a diagnostic on the standard error stream (ISO/IEC 9899:2024, 7.23.3) in an implementation-defined format and calls abort().
    The diagnostic contains #__VA_ARGS__ and information on the name of the source file, the source line number, and the name of the enclosing function (such as provided by source_location​::​current()).
If __VA_ARGS__ does not expand to an assignment-expression, the program is ill-formed.
The macro assert is redefined according to the current state of NDEBUG each time that <cassert> is included.
An expression assert(E) is a constant subexpression, if

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant