Connecting Tech Pros Worldwide Help | Site Map

setjmp/longjmp query.

  #1  
Old November 22nd, 2008, 03:05 AM
sh.vipin@gmail.com
Guest
 
Posts: n/a
Based on some study about setjmp / longjmp I have developed following
notions about setjmp / longjmp .
Would like to get feedback on them ??

Q1. Is there any point in keeping jmp_buf variable local to a
function. Because if the variable is local then any other function can
not return to this state (without using any other global variable)
because jmp_buf variable is local to caller function. And if doing
error handling within a function only can be achieved using goto
itself which will be more efficient. If one has to do the error
handling across multiple functions it must use global "jmp_buf"
variable.

Q2. When doing real error handling in C Programs across different
function calls, we will always have to keep jmp_buf variable global.
Becasue when we want to make longjmp call we must know which variable
to return. Just for above reason.

Q3. When there is a hierarchy of function calls, you can save the
state at multiple places in different jmp_buf variables. Now when
making longjmp call, it must know at which place to return. There
doesn't seem to be a way of returning by default to place where last
setjmp call was made (i.e. there is nothing similar to associating
else with last if ). Though that makes sense as C doesn't support
full syntax support for error handling like C++(i.e. try catch).
Although everything seems achievable by some macro writing and
overriding.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
State Machines and Coroutines Deiter answers 11 January 8th, 2006 07:35 PM