Connecting Tech Pros Worldwide Forums | Help | Site Map

setjmp/longjmp query.

sh.vipin@gmail.com
Guest
 
Posts: n/a
#1: Nov 22 '08
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 C / C++ bytes