setjmp.h in C

setjmp.h in C

The file header named setjmp.h in C Library defines the macro setjmp (), a longjmp () function, and a variable type jmp_buf, to ignore the regular function call and return the rule, by providing methods mode to perform jumps while maintaining the function call environment.

The variable is defined in setjmp.h

Here is the type of variable defined in setjmp.h:

jmp_buf : This is an array type used to hold information for the setjmp () macro and longjmp () function.

The macros are defined in setjmp.h

There is only one macro defined in this library:

int setjmp (jmp_buf environment) : This macro stores the current environment inside the environment variable for later use by longjmp (). If this macro returns directly from the macro call, it returns 0; but if it returns from a call to longjmp (), a value other than 0 is returned.

Macro declaration setjmp () in C

Below is the declaration for setjmp () macro.

 int setjmp (jmp_buf environment) 

Parameters:

environment - This is an object of type jmp_buf where environment information is stored.

Return value:

This macro returns more than 1 time. First, on its direct call, it always returns 0. When longjmp is called with the information set to the environment, this macro returns again; this time it returns the value passed to longjmp as the second parameter.

For example:

The following C program illustrates the usage of setjmp () macro.

 #include 
#include
#include

main ()
{
jmp_buf env;
int i;

i = setjmp (env);
printf ("i =% dn", i);

if (i! = 0) exit (0);

longjmp (env, 2);
printf ("Is it printed now?");

}

Compiling and running the above C program will result:

 i = 0 
i = 2

The functions are defined in setjmp.h

Only one function is defined in setjmp.h:

Function longjmp void (jmp_buf environment, int value): This function restores the environment (environment) stored by the closest call to the setjmp () macro in the same function call of the program with the corresponding parameter jmp_buf.

Declare the function longjmp () in C

Below is the declaration for longjmp () function in C:

 void longjmp (jmp_buf environment, int value) 

Parameters:

environment - This is an object of type jmp_buf that contains information to store the environment at the call point of setjmp.
value - This is the value for the setjmp expression to estimate.

Return value:

This function does not return any values.

For example:

The following program C illustrates the usage of the longjmp () function in C:

 #include 
#include
#include

main ()
{
jmp_buf env;
int i;

i = setjmp (env);
printf ("i =% dn", i);

if (i! = 0) exit (0);

longjmp (env, 2);
printf ("Is it printed now?");

}

Compiling and running the above C program will result:

 i = 0 
i = 2

According to Tutorialspoint

Last lesson: math.h in C

Next post: signal.h in C

4 ★ | 1 Vote

May be interested

  • Check out the 'buffalo' Pokémon in Pokémon GoCheck out the 'buffalo' Pokémon in Pokémon Go
    each type of pokemon has hp, cp, ability to attack and endure differently. based on these indicators, players can determine as well as choosing the most powerful pokemon for their offensive tactics.
  • Sitting home can also locate Pokemon around, do you believe it?Sitting home can also locate Pokemon around, do you believe it?
    the tightening of the niantic developers' rules to prevent players from abusing the support tools also brings annoyance, such as those who have no conditions to move much, go away, it is hard to know. get the location of the pokemon around the area they live in
  • 5 undeniable benefits when playing Pokemon Go5 undeniable benefits when playing Pokemon Go
    get to know many new people, breathe fresh air, relieve stress, increase concentration thanks to going out for a walk .... are compelling reasons to force you to try pokemon go now .
  • Want to earn the fastest Pokécoins in Pokémon Go? So don't miss this article!Want to earn the fastest Pokécoins in Pokémon Go?  So don't miss this article!
    pokécoins in pokémon go play the role of buying items in the store. the more coins you earn, the more likely you are to buy more items. to earn pokécoins, players will have to complete certain tasks or buy real money.
  • Pokémon systems when fighting in Pokémon GoPokémon systems when fighting in Pokémon Go
    each pokémon system in pokémon go has different strengths, along with a specific weakness. this type of pokémon will have the power to attack the other pokémon, but can defeat the other pokémon. if you know the characteristics of each type, it will be easier to choose which pokémon to battle.
  • The terms you need to know when playing Pokémon GoThe terms you need to know when playing Pokémon Go
    pokémon go is the most prominent name in recent days. this game of capturing and training virtual animals has created a relatively new way of playing, as players have to constantly move to catch pokémon. during the process of joining pokémon go, you will encounter and use a lot of important terms. so what do they mean?
  • How to play Pokemon GO on Windows computersHow to play Pokemon GO on Windows computers
    recently, pokemon go has become a popular game, attracting thousands of gamers around the world. in previous posts network administrator has guided you on how to play pokemon go on android devices and ios devices. in the article below, network administrator will guide you how to play pokemon go on windows computers using bluestacks emulator software.
  • How to become a good Pokémon Go hunter?How to become a good Pokémon Go hunter?
    with a new way of playing, pokémon go has created a new phenomenon in the game village around the world. players will have to go around and find pokémon for themselves. so how to quickly catch pokémon and in large numbers?
  • Things to know to upgrade Pokémon in Pokémon GoThings to know to upgrade Pokémon in Pokémon Go
    the whirlwind pokémon go has spread its power right on the first day of its release. everyone rushed to the street to find a pokémon for themselves. therefore, in order to become a pokémon hunter, you need to master the basics of participating in pokémon go battlefield.
  • List of medals received in Pokemon GoList of medals received in Pokemon Go
    in addition to getting items when leveling up, gamers who join pokemon go also have the opportunity to receive their proud achievements.