Full prototype:

int setjmp(jmp_buf);  

Purpose and Notes:

A macro that saves information about the point it is called into the jmp_buf argument that is passed in as the only argument. Later calls to longjmp can return the execution of the code to the point of the setjmp with the saved state.

Used as a way to "jump" between multiple points of the code even if they are not in the same function and scope.

To say this function is controversial is putting it mildly as it is HATED by many programmers. People hate the spaghetti code it can cause and the mental overhead of being able to jump to different parts of the code all willy nilly.


int- Returns a zero if the call of the function was from direct invocation, and it returns non-zero if it was called after an a call to longjmp brought you back. The longjmp function determines what the return value will be or 1 by default.

Argument 1:

jmp_buf- A special variable to save the current state of execution into. This can later be used by the longjmp function to return to this point in the code from basically anywhere with the saved state.

Example 1