Hello guys I have a short question, that I need to understand. I just want to enable a piece of code in the entire project that works only in debugging mode. so I want like a macro let's say:
1 2 3
#if DEVELOPMENT
// code here..
#endif // DEVELOPMENT
so that code will only be active on Debugging.
So.. where do I have to define #DEVELOPMENT 1 to work with the compiler when I change it to Debug and #DEVELOPMENT 0 when I change to Release mode ?
.. Thank you.
Well for MSVS, there is the pre-defined macro _DEBUG which is defined as 1 when the /LDd, /MDd, or /MTd compiler option is set. Otherwise it's undefined.
Ahh.. okay .. That's only for MSVS..
Thank's Andy I work in that way .. but I saw ppl. doing that I didn't realize is only a MSVS pre-defined macro.
So last think .. can someone add a defined macro such as seeplus said. manually ?
Or I have to resign and use as I did before.. and Andy said.
If you find your-self using this or others put them in a header file and include the header file.
It should not matter where it is defined just that it is defined and the header file would be included in the source code before any of the macros would be used.
You can define the macro on the command line. For g++:
g++ -DDEBUG=1 -o myfile myfile.cpp
Depending on your build environment, there should be a way to define it when doing a development build and leave it out when doing a production build.
The advantage of defining it on the command line is that you don't have to worry about forgetting to define it in some file, or defining it in one file and leaving it out in another.