ASSERT(3POSIX)
๐ ASSERT(3POSIX) ๐
okay bestie, gather round, because this is the POSIX Programmer's Manual page for assert, and she is lowkey the most iconic little macro in the whole header file. ๐
๐จ PROLOG ๐จ
So, real talk: this manual page is part of the POSIX Programmer's Manual. But heads up โ the Linux implementation of this interface may differ, so like, consult the corresponding Linux manual page for the actual details of Linux behaviour. Or, plot twist, the interface might not even be implemented on Linux at all. ๐ Not me warning you twice, but here we are.
โจ NAME โจ
assert โ insert program diagnostics ๐ฉบ
๐ SYNOPSIS ๐
#include <assert.h>
void assert(scalar expression);
๐ธ DESCRIPTION ๐ธ
Okay so first things first, the functionality on this reference page is aligned with the ISO C standard. Any conflict between what's written here and the ISO C standard is unintentional โ no drama intended, fr fr. This volume of POSIX.1-2017 defers to the ISO C standard.
The assert() macro shall insert diagnostics into programs, and it shall expand to a void expression. Periodt. ๐ซถ
Now here's the part where she gets to work. When assert() is executed, if expression โ which shall have a scalar type โ is false (that is, it compares equal to 0), then assert() shall:
- write information about the particular call that failed on
stderr๐ญ - and shall call
abort()
The info it writes about that failed call shall include all of these:
- the text of the argument
- the name of the source file
- the source file line number
- the name of the enclosing function
and those last three are, respectively, the values of the preprocessing macros __FILE__ and __LINE__, and of the identifier __func__. It's giving receipts. ๐งพโจ
And now the glow-down (affectionate): forcing a definition of the nameNDEBUGโ either from the compiler command line, or with the preprocessor control statement#define NDEBUGplaced ahead of the#include <assert.h>statement โ shall stop assertions from being compiled into the program. Poof, gone, no more checks. ๐
๐ RETURN VALUE ๐
The assert() macro shall not return a value. That's it, that's the whole section. No notes. ๐
โ ๏ธ ERRORS โ ๏ธ
No errors are defined.
The following sections are informative. ๐
๐ซ EXAMPLES ๐ซ
None. ๐ (She's self-explanatory, iykyk.)
๐ ๏ธ APPLICATION USAGE ๐ ๏ธ
None. ๐
๐ง RATIONALE ๐ง
None. ๐
๐ฎ FUTURE DIRECTIONS ๐ฎ
None. โญ
๐ SEE ALSO ๐
abort()stdin
The Base Definitions volume of POSIX.1-2017, <assert.h> ๐
ยฉ๏ธ COPYRIGHT ยฉ๏ธ
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! ๐ฆ this iconic little writeup is brought to you by IEEE/The Open Group, 2017 โ mwah, thanks for the lore, love you, bye! ๐๐๐
๐ฆ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 ยท Other
- debian trixie: manpages-posix-dev 2017a-2 ยท Other
- ubuntu jammy: manpages-posix-dev 2017a-2 ยท Other
- ubuntu noble: manpages-posix-dev 2017a-2 ยท Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms