setjmp


#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>

int main (void) {
    jmp_buf env;
    int val;

    /* Ortamı kaydetme */
    val = setjmp(env);

    if(val!=0) {
       printf("Bu noktaya longjmp() fonksiyonu ile ve %d değeri ile erişim sağlandı!", val);
       exit(0);
    }

    printf("longjmp() fonksiyon çağrısı.\n");
    longjmp(env, 7);

    return 0;
}


4
1

                                    #include &lt;sys/stat.h&gt;#include &lt;unistd.h&gt;#include &lt;fcntl.h&gt;#include &lt;stdlib.h&gt;#include &lt;errno.h&gt;#include &lt;stdio.h&gt;#include &lt;setjmp.h&gt; static jmp_buf env; static void f2(void){	printf(&quot;f2... \n&quot;); 	longjmp(env, 2);} static void f1(int argc){	printf(&quot;f1... \n&quot;);	if (argc == 1)		longjmp(env, 1); 	// Return to the place where setjmp was called. At this time, because env 1 is set, setjmp will return 1.	 f2 (); // Return above, f2 does not execute} int main(int argc, char *argv[]){	switch (setjmp(env)) {		 case 0: / * returns 0 after calling setjmp (), execute the following * /			printf(&quot;Calling f1() after initial setjmp()\n&quot;);			f1(argc);              		break;                  		 case 1: // longjmp (env, 1); setjmp will return 1, execute here			printf(&quot;We jumped back from f1()\n&quot;);		break; 		case 2:			printf(&quot;We jumped back from f2()\n&quot;);		break;				default:			printf(&quot;default \n&quot;);		break;	} 	return 0;}       

4 (1 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source