Jump to content

C++ Programming/Code/Standard C Library/Functions/setjmp

From Wikibooks, open books for an open world

setjmp

[edit | edit source]
Syntax
#include <csetjmp>
int setjmp( jmp_buf env );

The function setjmp() stores the current execution status in env, and returns 0. The execution state includes basic information about which code is being executed in preparation for the longjmp() function call. If and when longjmp is called, setjmp() will return the parameter provided by longjmp - however, on the second return, variables that were modified after the initial setjmp() call may have an undefined value.

The buffer is only valid until the calling function returns, even if it is declared statically.

Since setjmp() does not understand constructors or destructors, it has been superseded with the C++ exception system, which uses the throw and catch keywords.

Note:
setjmp does not appear to be within the std namespace.

Related topics
longjmp