Re: Why the setjmp and longjmp I wrote can not work?
From: Paul Pluzhnikov (ppluzhnikov-nsp_at_charter.net)
Date: Sun, 06 Nov 2005 12:17:10 -0800
"Zheng Da" <email@example.com> writes:
> #include <stdio.h>
Your program as posted doesn't compile:
junk.c: In function `mysetjmp':
junk.c:13: error: subscripted value is neither array nor pointer
junk.c:16: error: subscripted value is neither array nor pointer
... etc ...
Fixing these ...
> When the computer execute jmp %2, and gives me a segment fault.
Nope. It crashes *before* it reaches that instruction.
Learn to use the debugger to figure that out.
> I do not know why the address I save is a invalid address, and wonder
> to know what should I do if I want that mysetjmp and mylongjmp can work
The 'mylongjmp' can't be reasonably implemented with inline assembly.
You'll have to use "pure" assembly if you are to have any chance
of success. Also note that setjmp/longjmp must save *all* registers.
At a minimum you must save/resore %esp in addition to %ebp.
-- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email.