SETJMP(3POSIX)
π SETJMP β the POSIX programmer's manual, but make it cute π
okay bestie, before we even start: this page lives in the POSIX Programmer's Manual. But heads up β the Linux version of this interface might act different (so go check the matching Linux man page for the actual Linux tea β), or it might not even be implemented on Linux at all. Not every platform is gonna have this one, and that's just facts. π
β¨ NAME β¨
setjmp β set a jump point for a non-local goto, aka planting a little flag so you can teleport back to it later π©
πΈ SYNOPSIS πΈ
#include <setjmp.h>
int setjmp(jmp_buf env);
that's it, that's the whole vibe check π
π¦ DESCRIPTION π¦
okay so everything on this page is aligned with the ISO C standard. If anything here ever clashes with the ISO C standard? Totally unintentional, no drama intended. This volume of POSIX.1β2017 defers to the ISO C standard. periodt.
A call to setjmp() shall save the calling environment into its env argument, so longjmp() can come back to it later. it's giving "bookmark but for execution state" π
Now here's a lil mystery for you: it is unspecified whether setjmp() is a macro or a function. So if a macro definition gets suppressed just so you can reach an actual function, or if a program defines an external identifier named setjmp β that's undefined behavior, bestie. do not do that. π
An application shall make sure that an invocation of setjmp() shows up in one of these contexts only:
- The entire controlling expression of a selection or iteration statement
- One operand of a relational or equality operator with the other operand an integral constant expression, with the resulting expression being the entire controlling expression of a selection or iteration statement
- The operand of a unary
'!'operator with the resulting expression being the entire controlling expression of a selection or iteration - The entire expression of an expression statement (possibly cast to
void)
And if your invocation shows up in any other context? Undefined behavior. literally nowhere else, she said what she said π«
π RETURN VALUE π
- If the return is from a direct invocation,
setjmp()shall return0. - If the return is from a call to
longjmp(),setjmp()shall return a non-zero value.
zero means "hi I just got here", non-zero means "I've been sent back". iconic behavior honestly β¨
π ERRORS π
No errors are defined.
The following sections are informative. (translation: the important stuff is done, everything below is bonus content π)
π EXAMPLES π
None. she's mysterious like that π
π«Ά APPLICATION USAGE π«Ά
ngl, in general sigsetjmp() is more useful when you're dealing with errors and interrupts popping up in a low-level subroutine of a program. so if that's your situation, maybe go say hi to her instead π
β RATIONALE β
None.
π§ FUTURE DIRECTIONS π§
None.
π₯ SEE ALSO π₯
longjmp()sigsetjmp()
And from the Base Definitions volume of POSIX.1β2017: <setjmp.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 .
πΈ that's a wrap bestie!! this absolute classic was brought to you by IEEE/The Open Group, dated 2017, from the SETJMP(3POSIX) page of the POSIX Programmer's Manual. go plant your jump point, save your env, and slay ππ¦β¨
π¦ 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