S
someone
I have *thought* that setjmp/longjmp() should take a pointer to
jmp_buf. And the calling function should hold the actual struct data.
But ... I trid on both Win32 and Linux, it seems that
setjmp/longjmp() are taking stuct:
c:\> dmc sj.c (Digital Mars Compiler Version 8.38n)
link sj,,,user32+kernel32/noi;
c:\> sj.exe
sizeof(jmp_buf) = 64
----------------------------------------------------------------- sj.c
-----
#include <setjmp.h>
#include <stdio.h>
int main()
{
printf("sizeof(jmp_buf) = %d\n", sizeof(jmp_buf));
return 0;
}
----------------------------------------------------------------- sj.c
-----
And on Linux:
[d] ./sj
sizeof(jmp_buf) = 156
I'm totally confused. The jmp_buf is used to store the program state
info in setjmp(), and the info will be used again when longjmp is
called.
However in C, struct is pass-by-copy; so the calling function's
jmp_buf will not be modified, because setjmp() can only modify it's
own copy of jmp_buf. Then where is the info stored, and how longjmp()
can use the saved info to jump back?
What's the magic behind, or I miss something?
Can you try my example? and can you give an explanation?
Thanks.
jmp_buf. And the calling function should hold the actual struct data.
But ... I trid on both Win32 and Linux, it seems that
setjmp/longjmp() are taking stuct:
c:\> dmc sj.c (Digital Mars Compiler Version 8.38n)
link sj,,,user32+kernel32/noi;
c:\> sj.exe
sizeof(jmp_buf) = 64
----------------------------------------------------------------- sj.c
-----
#include <setjmp.h>
#include <stdio.h>
int main()
{
printf("sizeof(jmp_buf) = %d\n", sizeof(jmp_buf));
return 0;
}
----------------------------------------------------------------- sj.c
-----
And on Linux:
[d] ./sj
sizeof(jmp_buf) = 156
I'm totally confused. The jmp_buf is used to store the program state
info in setjmp(), and the info will be used again when longjmp is
called.
However in C, struct is pass-by-copy; so the calling function's
jmp_buf will not be modified, because setjmp() can only modify it's
own copy of jmp_buf. Then where is the info stored, and how longjmp()
can use the saved info to jump back?
What's the magic behind, or I miss something?
Can you try my example? and can you give an explanation?
Thanks.