Added setjmp_test.cpp

This commit is contained in:
anon 2024-03-10 15:57:36 +01:00
parent c918e4de5e
commit d3462ed95a

26
setjmp_test.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <setjmp.h>
void f(int* a, int* b){
*a += 3;
*b += 5;
}
signed main(){
int* heap_var = new int(1);
int stack_var = 2;
jmp_buf buf;
int j = setjmp(buf);
printf("heap: %d\nstack: %d\n---\n", *heap_var, stack_var);
if(j){
return 0;
}
f(heap_var, &stack_var);
longjmp(buf, 1);
}