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 name NDEBUG โ€” either from the compiler command line, or with the preprocessor control statement #define NDEBUG placed 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> ๐Ÿ“š


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