Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>exit_popstate</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
exit_popstate
exit_pushstate

Usage

   #include <exitstat.h>
   int exit_popstate(int a);
   void exitpushstate(void)

Description

   These functions push and pop the program exit frame so that exit and
   atexit return points can be intercepted and controlled. This is useful in
   Microsoft Windows programming and for turning a stand-alone program in to
   a subroutine. A maximum of 16 states can be saved.

   exit_pushstate will set the integer variable passed to it by reference
   to the return state + 1, sent via any exit() statement encountered before
   a matching exit_popstate has been reached. If an exit() is encountered,
   an exit_popstate is automatically executed and should not be performed
   again. The atexit() function list contains no functions after an
   exit_pushstate is performed, even if there had been previous calls to
   atexit(). These functions will be returned to the atexit() function list
   when a matching exit_popstate or an exit() is reached.

Example 1

   /* example usage: */

   int  a;

   if (exit_pushstate(a) == 0)
   {
       sub();              // your functions that may call exit
       exit_popstate();

                           // only call if exit_pushstate returns 0
   } else {
       --a;                // a == return value now,
   }                       // exit_pushstate always returns exit

        ...


   void sub()
   {
       ...
       exit(2);            // rather than exit program,
   }                       // this will 'call up' to exit_pushstate
                           // and then drop down to the else case
                           // with a == 3

Example 2: atexit chaining

   /* example usage: */

   void goodbye_world(void)
   {
       printf("goodbye\n");
   }

   void hello_world(void)
   {
       printf("hello\n");
   }

   void foo(void)
   {
       int  a;

       atexit(goodbye_world);
       if (exit_pushstate(a) == 0)
           {
           atexit(hello_world);
           sub();                  // your functions that may
                                   // call exit

           exit_popstate();        // only call if exit_pushstate
                                   // returns 0
       } else {
           --a;                    // a == return value now,
       }                           // exit_pushstate always
                                   // returns exit value + 1
   exit(1);                        // this exit will exit the
                                   // program entirely but
                                   // before the exit occurs
                                   // goodbye_world will be
                                   // executed
   }

   void sub()
   {
       ...
       exit(2);                    // rather than exit program,
   }                               // this will 'call up' to
                                   // exit_pushstate
                                   // and then drop down to the

                                   // else case with a == 3
                                   // before the call up occurs
                                   // however, the hello_world
                                   // function will be executed

Return Value

   exit_pushstate will set the integer variable passed to it by reference
   to the return state + 1, sent via any exit() statement encountered before
   a matching exit_popstate has been  reached.





Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson