add setjmp

This commit is contained in:
LingZhaoHui 2020-08-02 11:27:26 +08:00
parent 944e0b9f85
commit fc76ba1cf6
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include <setjmp.h>
jmp_buf buf;
void banana(void)
{
printf("in banana() \n");
longjmp(buf, 1);
/* 一下代码不会被执行 */
printf("you'll never see this, because i longjmp'd");
}
int main(void)
{
if (setjmp(buf)){
printf("back in main \n");
}else{
printf("first time throught\n");
banana();
}
return 0;
}