Created
October 16, 2018 10:04
-
-
Save Dysta/853b97844f901e49351912ef119226a4 to your computer and use it in GitHub Desktop.
Introduction à setjmp et longjmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <setjmp.h> | |
volatile /* utilisation du mot clé volatile lorsqu'on compile en -O3 */ int i = 0; | |
jmp_buf b; | |
void f( void ) { | |
longjmp(b, ++i); | |
} | |
/* ne fonctionne pas car on ne peut pas déscendre dans la pile */ | |
int g( void ) { | |
return setjmp(b); | |
} | |
int main(int argc, char const *argv[]) { | |
printf("Boucle jmp1\n"); | |
if ( setjmp(b) < 10 ) { | |
printf("%d\n", i); | |
f(); | |
} | |
i =0; | |
printf("Boucle jmp2\n"); | |
if ( g() < 10 ) { | |
printf("%d\n", i); | |
longjmp(b, ++i); | |
} | |
printf("Boucle for \n"); | |
for ( i = 0; i < 10; i++) | |
{ | |
printf("%d\n", i); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Merci Dysta t le bro