Advertisement
homer512

trace C++

Jun 16th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <vector>
  2. // using std::vector
  3. #include <cstdio>
  4. // using std::printf
  5.  
  6. std::vector<const char*> calltrace;
  7.  
  8. #define trace(x) calltrace.push_back(#x); x; calltrace.pop_back();
  9.  
  10. namespace {
  11.   void foo(int z)
  12.   {
  13.     std::printf("Calltrace contains:\n");
  14.     for(std::vector<const char*>::iterator i = calltrace.begin(),
  15.       end = calltrace.end(); i != end; ++i)
  16.       std::printf("\t%s\n", *i);
  17.     std::printf("\n");
  18.   }
  19.  
  20.   void bar()
  21.   {
  22.     int x = 0, y = 1;
  23.     trace(int z = x + y)
  24.     trace(foo(z))
  25.   }
  26. }
  27.  
  28. int main()
  29. {
  30.   trace(bar())
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement