Anything starting with a #…
is an instruction to the C++ preprocessor which runs before the actual C/C++ compiler; the preprocessor constructs the final source code for the compiler.
So here is what’s happening when your program compiles.
Step one: preprocess
The preprocessor reads your code top down and executes the instructions.
#define _GLIBCXX_DEBUG 1
Set a flag called _GLIBCXX_DEBUG
to 1
.
#include <vector>
#include <iostream>
Read the file vector.h
and iostream.h
from whatever your compiler’s include path is. That file contains more C/C++ code and also preprocessor instructions which are now recursively unfolded. Some of that code may look like
#if _CLIBCXX_DEBUG
prinf("Print me to debug!");
#endif
and this code shows up in your final C/C++. If your _CLIBCXX_DEBUG
is 0
then the code won’t be there. The net effect is that you can put together your code before compiling it.
In your case that extra code adds special tests into your final C/C++ file which cause the error message you see. When you switch lines, the flag won’t be set when the #include
are processed, thus these special tests won’t be added into your source.
See this question on how to dump the final C/C++ code that’s actually being compiled.
Step two: compile
Once your C/C++ source code file has been preprocessed (i.e. stuff included, conditionally unfolded, etc…) then the actual compiler is invoked to build your code.
Is there a way to toggle debug mode on another line in the program (without compiler flags)?
Change the value of that flag throughout your code as you need it.