### Roufie's blog

By Roufie, history, 6 weeks ago,

Hi,

I'm new to Codeforces and have been looking code into submissions by others. I'm new to C++ as well and can't find any articles on what these snippets of code do. Can someone please explain?

I understand that the code in If block gets executed when LOCAL is set. But what does the code actually do? What is alog/debug.g? What is debug(...) 42 meant for?

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

#ifdef LOCAL
#define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
#else
#define eprintf(...) 42
#endif


• +12

 » 6 weeks ago, # | ← Rev. 2 →   +42 .h is called a header file, and is basically a library of code that either you make (or downloaded), or it comes with the compiler. Content-wise, it looks just like a C++ source file without a main()A demonstration will be useful. Do the following: Make a C++ file like how you usually do on your computer. Paste this code in. something.cpp#include #include "algo/sum.h" using namespace std; int main() { cout << sum(1, 2) << endl; }  Make a folder named algo, in the same folder with your C++ file. Make a file named sum.h inside algo, then paste this code. sum.hint sum(int a, int b) { return a+b; }  Now run the C++ code (the "something.cpp" file) You can do include in the header file, or add more stuff inside that header file, or add even more header files to the algo folder, or do any customizations you want to make your own algo library. debug.h is probably just their own custom-made header file for debugging CP codes if needed. You might be able to find some online, or you can make one by yourself.
•  » » 6 weeks ago, # ^ |   +1 Thanks for the answer!Adding a few more details:As MidoriFuse has explained algo/debug.h is a library used to help with debugging. Here is a sample debug.h file -> https://github.com/sanathkumarx/Competitive-Coding/blob/master/CodeForces/practice/algo/debug.h#ifdef LOCAL flag which is set locally by passing the command line arg -DLOCAL when compiling the program. Whenever this flag is passed debug(...) function's definition will be#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)Otherwise debug(...) function's definition will get set to 42; which does nothing and gets ignored. Refer comments in: https://codeforces.com/blog/entry/99946This is very useful, as you would not need to remove all your debug() statements when you are submitting code online.
•  » » » 6 weeks ago, # ^ |   0 Why use 42 though? Is there any specific reason or just a randomly chosen number?
•  » » » » 6 weeks ago, # ^ | ← Rev. 2 →   0 Randomly chosen. Also: Answer to everything
 » 6 weeks ago, # |   0 Stop trying to figure out how um_nik's mind works, you are doing it wrong, go and solve some problems.Some jokes. IMO, as u accumulating more knowledge and implementing more and more code, at any unknown moments, u could unexpectedly understand some things that could seemed weird before. U would only find something brainy(helpful) when its meeting your current demands/situation.More specifically, u may understand the use of the mentioned code when u are writing some “large” problems or u simply want to code faster.
•  » » 6 weeks ago, # ^ |   0 Curiosity doesn't always kill the cat :p