I saw this debug print for c++ here on stackoverflow but I can't comment it (I'm a newbie):
#ifdef DEBUG
#define dout cout
#else
#define dout 0 && cout
#endif
It is used like this:
dout << "in foobar with x= " << x << " and y= " << y << '\n';
At first sight I liked it, but I compile with -Wall, so I get a lot of warnings like
test1.cc:30:46: warning: statement has no effect [-Wunused-value]
Is there a way to reconcile -Wall and the stream oriented debug print?
This can be further refined, but try this as starting point:
#ifdef DEBUG
#define LOG_DEBUG( stuff ) { std::cout << stuff << std::endl; }
#else
#define LOG_DEBUG( stuff )
#endif
Then later in the code:
LOG_DEBUG( __FILE__ << " bla bla bla " << foo );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With