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