homer512 icon

trace C++

homer512 | PRO | 06/16/14 08:37:51 PM UTC | 0 ⭐ | 721 👁️ | Never ⏰ | []
C++ |

560 B

|

None

|

0 👍

/

0 👎

#include <vector>
// using std::vector
#include <cstdio>
// using std::printf
 
std::vector<const char*> calltrace;
 
#define trace(x) calltrace.push_back(#x); x; calltrace.pop_back();
 
namespace {
  void foo(int z)
  {
    std::printf("Calltrace contains:\n");
    for(std::vector<const char*>::iterator i = calltrace.begin(),
      end = calltrace.end(); i != end; ++i)
      std::printf("\t%s\n", *i);
    std::printf("\n");
  }
 
  void bar()
  {
    int x = 0, y = 1;
    trace(int z = x + y)
    trace(foo(z))
  }
}
 
int main()
{
  trace(bar())
}

Comments