c++ reference function inside function
===

The following is a simplified example of my scenario (which is very common it seems);

    #include <signal.h>

    void doMath(int &x, int &y);
    void signal_handler(int signal);

    int main() {
      signal (SIGINT,my_handler);
      int x = 10;
      int y;
      doMath(x,y);
      while(1);
      return 0;
    }

    void doMath(int &x, int &y) {
      for(int y=0; y<=x; y++) {
        cout << y << endl;
      } 
      return;
    }

    void signalHandler(int signal){
      doMath(x,y);
      exit(1);
    }

This basic program prints 1 to 10 on the screen and just hangs there until CTRL+C is pressed. At this point I want the doMath() function to run again. The only way I can see this happening is if I pass x and y to signalhandler() so it can then pass them onto doMath(), and a reference to the doMath() function also.

It my actual program there are two doMath() functions is many more variables, I would like a final dump of the variable values. So, it seems like an inefficient way passing all those variables to signalHandler to then be passed on to the two functions. Is there another way around this?

