A data type used by the `setjmp` and `longjmp` functions to store information about the program’s environment, including the stack, register states, and instruction pointer, allowing for non-local jumps in program execution.
1st Parameter
An object of type `jmp_buf` that contains the environment to restore, previously saved by a call to `setjmp`.
2nd Parameter Type : int
Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
2nd Parameter
The value to be returned by the corresponding `setjmp` call. If `val` is 0, it is replaced by 1.
Read more about parameters of longjmp in parameters section
The longjmpfunction in C language Restores the environment saved by setjmp with a specified return value.
The longjmp function restores the environment saved by the most recent invocation of setjmp in the same invocation of the program, with the corresponding jmp_buf argument. If there has been no such invocation, or if the function containing the invocation of setjmp has already returned, the behavior is undefined. After longjmp is completed, program execution continues as if the corresponding invocation of setjmp had just returned the value specified by val.
The longjmpfunction takes 2
parameters:
•
jmp_buf `env`: An object of type `jmp_buf` that contains the environment to restore, previously saved by a call to `setjmp`.
•
int `val`: The value to be returned by the corresponding `setjmp` call. If `val` is 0, it is replaced by 1.
Performs a non-local jump by restoring the environment saved in `env` (by `setjmp`) and causing `setjmp` to return the value `val`. Used for error handling or control flow, it does not return to the point of invocation but resumes execution at the `setjmp` call with the specified return value.
The longjmp function return value :
This function does not return
Output
This example demonstrates basic usage of longjmp in conjunction with setjmp to perform a non-local jump.