# HG changeset patch # User roug # Date 1036101932 0 # Node ID 23db189b671373fdc9ed6829eb66b15da2fa365a # Parent b3caab86dff9ae4784d1b1fc4e06f98a4f0b45c8 Several functions ready. diff -r b3caab86dff9 -r 23db189b6713 docs/ccguide/longjmp.refentry --- a/docs/ccguide/longjmp.refentry Thu Oct 31 22:05:32 2002 +0000 +++ b/docs/ccguide/longjmp.refentry Thu Oct 31 22:05:32 2002 +0000 @@ -1,7 +1,8 @@ -longjmp -Placeholder +Longjmp +Setjmp +jump to another function @@ -10,8 +11,14 @@ #include <setjmp.h> + setjmp + jmp_buf env + + + longjmp - type arg1 + jmp_buf env + int val @@ -19,7 +26,43 @@ Description -Placeholder +These functions allow the return of program control directly to +a higher level function. They are most useful when dealing +with errors and interrupts encountered in a low level routine. + + +"Goto" in C has scope only in the function in which it is +used; i.e. the label which is the object of a "goto" may only +be in the same function. Control can only be transferred +elsewhere by means of the function call, which, of course +returns to the caller. In certain abnormal situations a +programmer would prefer to be able to start some section of +code again, but this would mean returning up a ladder of +function calls with error indications all the way. + + +Setjmp is used to "mark" a point in the program where a +subsequent longjmp can reach. It places in the buffer, defined +in the header file, enough information for longjmp to restore +the environment to that existing at the relevant call to +setjmp. + + +Longjmp is called with the environment buffer as an argument +and also, a value which can be used by the caller of setjmp as, +perhaps, an error status. + + +To set the system up, a function will call setjmp to set up the +buffer, and if the returned value is zero, the program will +know that the call was the "first time through". If, however, +the returned value is non-zero, it must be a longjmp returning +from some deeper level of the program. + + +NOTE that the function calling setjmp must not have returned +at the time of calling longjmp, and the environment buffer must +be declared globally.