Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Dan

By: a guest on Feb 18th, 2010  |  syntax: C  |  size: 0.64 KB  |  views: 82  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. static int *address;
  4. void saveOrLaunch(int launch);
  5. void printA()
  6. {
  7.         printf("printA-Begin\n");
  8.         saveOrLaunch(0);
  9.         printf("printA-Return\n");
  10. }
  11. void printB()
  12. {
  13.         printf("printB-Begin\n");
  14.         saveOrLaunch(1);
  15.         printf("printB-Return\n");
  16. }
  17. void saveOrLaunch(int launch)
  18. {
  19.         int* ptr = &launch;
  20.         if (launch)
  21.                 ptr[-1] = address;
  22.         else
  23.                 address = ptr[-1];
  24. }
  25. int main()
  26. {
  27.         printf("Main:  Running printA\n");
  28.         printA();
  29.         printf("Main:  Running printB\n");
  30.         printB();
  31. }
  32.  
  33. /*
  34. $ ./a.out
  35. Main:  Running printA
  36. printA-Begin
  37. printA-Return
  38. Main:  Running printB
  39. printB-Begin
  40. printA-Return
  41. */
clone this paste RAW Paste Data