Bryma's blog

By Bryma, history, 3 years ago, In English

Hi ! I have a problem with debug in c++. I'm using this —

void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }

ifdef _DEBUG

define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

else

define dbg(...) 0

endif

When i type for example — int a = 5; dbg(a);

It's not showing any output.

  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Add -D_DEBUG to GCC command line on your local computer. And replace the line define dbg(...) cerr << "LINE(" << LINE << ") -> [" << with define dbg(...) cerr << "LINE(" << __ LINE__ << ") -> [" <<