Home > Blockchain >  How to make online compilers to ignore debug statements in C ?
How to make online compilers to ignore debug statements in C ?

Time:01-03

I am using these lines of code for debugging my C program.

    void dbg_out(){cerr << endl;}
    template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
    #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

But the problem with this is that when I am using dbg function and submit on an online judge like codeforces or codechef it is increasing execution of code. Is there a way to make the online compiler to ignore the debug statements ?

CodePudding user response:

You can make the preprocessor conditionally define the macro:

#ifdef DEBUG_LOG
  #define dbg(...) std::cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  #define dbg(...)
#endif

Now if you compile with the option -DDEBUG_LOG, the log would be sent to std::cerr. An online judge wouldn't add that command line option, but you can locally.

  • Related