“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
- Modulo Operator (%) in C/C++ with Examples
- fpclassify() method in C/C++ with Examples
- Operator Overloading '<<' and '>>' operator in a linked list class
- How to find the Entry with largest Value in a C++ Map
- getch() function in C with Examples
- Visibility Modes in C++ with Examples
- Chain of Pointers in C with Examples
- Pointer Expressions in C with Examples
- Speed up Code executions with help of Pragma in C/C++
- Vector of Vectors in C++ STL with Examples
- Introduction to the C99 Programming Language : Part I
- Jagged Array or Array of Arrays in C with Examples
- Introduction to the C99 Programming Language : Part III
- Introduction to the C99 Programming Language : Part II