sl@0
|
1 |
/** @file ../include/setjmp.h
|
sl@0
|
2 |
@internalComponent
|
sl@0
|
3 |
*/
|
sl@0
|
4 |
|
sl@0
|
5 |
/** @fn longjmp(jmp_buf __jmpb, int __retval)
|
sl@0
|
6 |
@param __jmpb
|
sl@0
|
7 |
@param __retval
|
sl@0
|
8 |
|
sl@0
|
9 |
Refer to setjmp() for the documentation
|
sl@0
|
10 |
|
sl@0
|
11 |
|
sl@0
|
12 |
|
sl@0
|
13 |
|
sl@0
|
14 |
@publishedAll
|
sl@0
|
15 |
@externallyDefinedApi
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
/** @fn setjmp(jmp_buf __jmpb)
|
sl@0
|
19 |
@param __jmpb
|
sl@0
|
20 |
|
sl@0
|
21 |
Note: This description also covers the following functions -
|
sl@0
|
22 |
longjmp() _setjmp() _longjmp()
|
sl@0
|
23 |
|
sl@0
|
24 |
@return If the return is from a direct invocation, the setjmp function returns 0. If the return is from a call to longjmp(),
|
sl@0
|
25 |
setjmp() returns a non-zero value.
|
sl@0
|
26 |
After the longjmp is completed, program execution continues as if
|
sl@0
|
27 |
the corresponding invocation of setjmp() had just returned the
|
sl@0
|
28 |
value specified by __retval. If __retval is 0, setjmp() returns 1.
|
sl@0
|
29 |
|
sl@0
|
30 |
The setjmp, and _setjmp functions save their calling environment in __jmpb. Each of these functions returns 0.
|
sl@0
|
31 |
|
sl@0
|
32 |
The corresponding longjmp functions restore the environment saved by their most recent respective
|
sl@0
|
33 |
invocations
|
sl@0
|
34 |
of the setjmp function.
|
sl@0
|
35 |
They then return so that program execution continues as if the corresponding
|
sl@0
|
36 |
invocation of the setjmp call had just returned the value specified by __retval, instead of 0.
|
sl@0
|
37 |
|
sl@0
|
38 |
The longjmp routines may not be called after the routine which called the setjmp routines returns.
|
sl@0
|
39 |
|
sl@0
|
40 |
All accessible objects have values as of the time longjmp routine was called, except that the values of objects of automatic storage
|
sl@0
|
41 |
invocation duration that do not have the volatile
|
sl@0
|
42 |
type and have been changed between the setjmp invocation and longjmp call are indeterminate.
|
sl@0
|
43 |
|
sl@0
|
44 |
The setjmp / longjmp pairs save and restore the signal mask while _setjmp / _longjmp pairs save and restore only the register set and the stack.
|
sl@0
|
45 |
|
sl@0
|
46 |
Examples:
|
sl@0
|
47 |
@code
|
sl@0
|
48 |
#include <setjmp.h>
|
sl@0
|
49 |
#include <stdio.h>
|
sl@0
|
50 |
#include <stdlib.h>
|
sl@0
|
51 |
|
sl@0
|
52 |
static void f1( int, int, int );
|
sl@0
|
53 |
static void f2( void );
|
sl@0
|
54 |
static jmp_buf jmpbuffer;
|
sl@0
|
55 |
|
sl@0
|
56 |
int main()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
int count;
|
sl@0
|
59 |
register int val;
|
sl@0
|
60 |
volatile int sum;
|
sl@0
|
61 |
|
sl@0
|
62 |
count = 2; val = 3; sum = 4;
|
sl@0
|
63 |
|
sl@0
|
64 |
if ( setjmp( jmpbuffer ) != 0 )
|
sl@0
|
65 |
{
|
sl@0
|
66 |
printf("in main: count = %d, val = %d, sum = %d
|
sl@0
|
67 |
", count, val, sum );
|
sl@0
|
68 |
exit(0);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
f1(97, 98, 99 );
|
sl@0
|
72 |
|
sl@0
|
73 |
return 0;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
static void f1 (int i, int j, int k )
|
sl@0
|
77 |
{
|
sl@0
|
78 |
printf("in f1: count = %d, val = %d, sum = %d
|
sl@0
|
79 |
", i, j , k );
|
sl@0
|
80 |
f2();
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
static void f2( void )
|
sl@0
|
84 |
{
|
sl@0
|
85 |
longjmp( jmpbuffer, 1 );
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
@endcode
|
sl@0
|
89 |
Output
|
sl@0
|
90 |
@code
|
sl@0
|
91 |
in f1: count = 97, val = 98, sum = 99
|
sl@0
|
92 |
in main: count = 2, val = 3, sum = 4
|
sl@0
|
93 |
|
sl@0
|
94 |
@endcode
|
sl@0
|
95 |
|
sl@0
|
96 |
Limitations:
|
sl@0
|
97 |
|
sl@0
|
98 |
The signal related functionalities aren't applicable to the Symbian
|
sl@0
|
99 |
OS implementation as there is no support for signals. This means that the setjmp and _setjmp routines have the same functionality and so do longjmp and _longjmp .
|
sl@0
|
100 |
|
sl@0
|
101 |
|
sl@0
|
102 |
|
sl@0
|
103 |
@publishedAll
|
sl@0
|
104 |
@externallyDefinedApi
|
sl@0
|
105 |
*/
|
sl@0
|
106 |
|
sl@0
|
107 |
|
sl@0
|
108 |
/** @def _setjmp
|
sl@0
|
109 |
|
sl@0
|
110 |
The _longjmp() and _setjmp() functions shall be equivalent to longjmp() and setjmp(), respectively, with the additional restriction that _longjmp() and _setjmp() shall not manipulate the signal mask.
|
sl@0
|
111 |
|
sl@0
|
112 |
@publishedAll
|
sl@0
|
113 |
@externallyDefinedApi
|
sl@0
|
114 |
*/
|
sl@0
|
115 |
|
sl@0
|
116 |
/** @def _longjmp
|
sl@0
|
117 |
|
sl@0
|
118 |
The _longjmp() and _setjmp() functions shall be equivalent to longjmp() and setjmp(), respectively, with the additional restriction that _longjmp() and _setjmp() shall not manipulate the signal mask.
|
sl@0
|
119 |
|
sl@0
|
120 |
@publishedAll
|
sl@0
|
121 |
@externallyDefinedApi
|
sl@0
|
122 |
*/
|