“Setjump” and “Longjump” are defined in setjmp.h, a header file in C standard library.
- setjump(jmp_buf buf) : uses buf to remember current position and returns 0.
- longjump(jmp_buf buf, i) : Go back to place buf is pointing to and return i .
Geek4 Welcome to GeeksforGeeks Geek3
The main feature of these function is to provide a way that deviates from standard call and return sequence. This is mainly used to implement exception handling in C. setjmp can be used like try (in languages like C++ and Java). The call to longjmp can be used like throw (Note that longjmp() transfers control to the point set by setjmp()).
This article is contributed by Aditya Chatterjee.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- mbrtowc() function in C/C++
- std::stoul and std::stoull in C++
- Print a number 100 times without using loop, recursion and macro expansion in C?
- C/C++ Tricky Programs
- Class template with multiple parameters
- Double Pointer (Pointer to Pointer) in C
- exec family of functions in C
- nextafter() and nexttoward() in C/C++
- memcpy() in C/C++
- A C Puzzle
- C++ program to print unique words in a file
- Predefined Identifier __func__ in C
- Pure Virtual Functions and Abstract Classes in C++
- Print 1 to 100 in C++, without loop and recursion
- What are the default values of static variables in C?