debugging - C++: Scoping issues when using a debug variable for a program -


I am writing a program, where I want to easily turn my debug code on / off. This program is not a production level - it is for a programming contest.

I have only one file, main.cpp , so I thought the debug variable could be acceptable. I consider using a global variable, as follows:

  bool DEBUG = true; Int main () {if the debug} {// print debug statements and other debug code} // The rest of the program ...   

However, I get a warning that my DEBUG variable is never used and if (DEBUG) is always evaluated for false. Alternatively, I use the main () method Inside your DEBUG variable:

  int main () {bool DEBUG = true; If the (debug) {// print debug statement and other debug code} // the rest of the program ...   

But then I get a compiler warning 'the condition is always true . Any suggestions on how to easily turn my DEBUG` code on / off? An explanation for compiler issues would be great.

Generally, the pre-processor is using

  # Ifndef NDEBUG // debug code #endif // or #ifdef DEBUG // debug code #endif   

Although a project I worked on NDEBUG was undefined and replaced with another So check that it exists.

I would not be surprised that your warning is because already exists #define DEBUG so your variable DEBUG is never used.

Usually DEBUG and NDEBUG are defined by the compiler.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -