B.6 Diagnostics: <assert.h>

The assert macro is used to add diagnostics to programs:

  void assert(int expression)

广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元

If expression is zero when

  assert(expression)

is executed, the assert macro will print on stderr a message, such as

  Assertion failed: expression, file filename, line nnn

It then calls abort to terminate execution. The source filename and line number come from the preprocessor macros __FILE__ and __LINE__.

If NDEBUG is defined at the time <assert.h> is included, the assert macro is ignored.