assert(3)
๐ assert(3) โ bestie's guide to yelling when things aren't true ๐
okay so real talk, this is assert(3) from the Standard C library (libc, -lc). it lives in the Library Functions Manual and it is genuinely one of the most iconic little macros in all of C, no cap. ๐
โจ NAME โจ
assert โ abort the program if assertion is false. that's it. that's the whole vibe. it checks a thing, and if the thing is a lie, your program gets absolutely ended. ๐
๐ธ LIBRARY ๐ธ
Standard C library (libc, -lc) ๐ซถ
๐ฆ SYNOPSIS ๐ฆ
#include <assert.h>
void assert(bool expression);
๐ DESCRIPTION ๐
so here's the tea, bestie: this macro helps programmers find bugs in their programs, or handle exceptional cases via a crash that will produce limited debugging output. it's like a little bodyguard for your assumptions. ๐
if expression is false (i.e., compares equal to zero ๐ญ), assert() prints an error message to standard error and terminates the program by calling abort(3). the error message includes the name of the file and function containing the assert() call, the source code line number of the call, and the text of the argument. something like:
prog: some_file.c:16: some_func: Assertion `val == 0' failed.
like, it literally snitches on exactly where and why and shows you the receipts. ๐ฅ
BIG ONE, pay attention ๐จ: if the macro NDEBUG is defined at the moment <assert.h> was last included, the macro assert() generates no code, and hence does nothing at all. poof. gone. no thoughts, head empty. it is not recommended to define NDEBUG if using assert() to detect error conditions, since the software may behave non-deterministically. so like, don't do that. ๐
warning bestie: if you're usingassert()to catch real errors and you defineNDEBUG, your software may behave non-deterministically. that is not the slay you think it is.
โญ RETURN VALUE โญ
No value is returned. it returns nothing. void. the void is the moment. โจ
๐ง ATTRIBUTES ๐ง
for an explanation of the terms used in this section, see attributes(7). ๐
- Interface:
assert() - Attribute: Thread safety
- Value: MT-Safe
so yeah, she's MT-Safe. safe in multithreaded situations, periodt. ๐
๐ STANDARDS ๐
C11, POSIX.1-2008. certified. official. we stan an internationally standardized macro. ๐โจ
๐ธ HISTORY ๐ธ
C89, C99, POSIX.1-2001.
and here's a little lore drop for you ๐ฐ๏ธ: in C89, expression is required to be of type int and undefined behavior results if it is not, but in C99 it may have any scalar type. glow-up fr fr. ๐
๐ BUGS ๐
okay so this one is important. assert() is implemented as a macro; if the expression tested has side-effects, program behavior will be different depending on whether NDEBUG is defined. this may create Heisenbugs which go away when debugging is turned on. ๐ญ
translation: if your expression does stuff (not just checks stuff) and you flip NDEBUG on or off, your program will legit behave differently. and you'll get one of those cursed bugs that vanishes the second you go looking for it. Heisenbugs. absolutely unhinged behavior. do not put side effects in your assertions, bestie. ๐ซถ
๐ SEE ALSO ๐
and that's the whole page, angel ๐ go forth and assert your truth (but like, only side-effect-free truths, okay?) ๐
this lil masterpiece is from Linux man-pages 6.20, dated 2026-02-08. mwah, xoxo, go read abort(3) next, iykyk. ๐๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Thomas Koenig <ig25@rz.uni-karlsruhe.de>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms