#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