ifdef#ifndef for ONLINE_JUDGE in C++

Revision en1, by KR1shna, 2020-03-30 10:03:19

It might be useful to some of us Look at the following piece of code in C++:

#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define macro1
#define macro2
...
#include "local_header1.h"
#include "local_header2.h"
...
#endif
//.....//


#ifndef stands for if_not_defined
#ifdef stands for if_defined

One can use preprocessor directives to make more debugs through your local device.
One can define some specific header files only to be used in local device not on online_judge
One can use macro as flags inside these #ifndef or #ifdef containers

Examples:
(1)

#ifndef ONLINE_JUDGE
#define covid19 text
#endif

#ifdef covid19
cout<<"Yes, its corona";
#endif

(Here, we used covid19 as flag to print something.)



(2)
Thanks to Errichto as I learned from him on YouTube
https://github.com/Errichto/youtube/blob/master/atcoder-dp/g.cpp
(You can see on the above link he used #ifdef LOCAL for debugging, this will print stuffs local to the device)



For more information consider the following links
https://gcc.gnu.org/onlinedocs/cpp/Macros.html
https://en.wikipedia.org/wiki/C_preprocessor

Tags preprocessor, c++, online_judge, macros, #ifdef, #ifndef, local

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en12 English KR1shna 2020-09-04 18:19:10 56
en11 English KR1shna 2020-04-19 11:20:30 59
en10 English KR1shna 2020-04-17 20:02:33 2
en9 English KR1shna 2020-04-16 06:57:10 20
en8 English KR1shna 2020-03-30 15:27:32 5
en7 English KR1shna 2020-03-30 15:26:53 140
en6 English KR1shna 2020-03-30 13:51:13 1
en5 English KR1shna 2020-03-30 13:47:26 2
en4 English KR1shna 2020-03-30 13:46:36 66
en3 English KR1shna 2020-03-30 13:41:09 828
en2 English KR1shna 2020-03-30 10:34:55 16
en1 English KR1shna 2020-03-30 10:03:19 1392 Initial revision (published)