_DEBUG vs DEBUG Preprocessor Macro

We are working on cross-platform development of Adobe InDesign plugins. On Mac, for Debug build, we define DEBUG macro (without underscore prefix) in Preprocessor Macro of Clang in XCode.

When we define "DEBUG" as the macro, XCode 9.3 clang compiler would not recognize "_DEBUG" used in the code. This was perfectly fine since "_DEBUG" was used in Windows.

However, in XCode 11.5, even though we define "DEBUG" in preprocessor, "_DEBUG" is recognized.

I want to understand as to why has this happened? Also, is there any way in the project setting to avert this?

PS: I know I can do this by adding #ifndef MACINTOSH. But, the client would like to explore a solution without this :-)


This seems to be something specific to your project. Consider this…

I used Xcode 12.5 to create a new project from the macOS > Command Line Tool > C template.

I replaced the body of the main function with this:

Code Block
#if DEBUG
printf("DEBUG set\n");
#else
printf("DEBUG clear\n");
#endif
#if _DEBUG
printf("_DEBUG set\n");
#else
printf("_DEBUG clear\n");
#endif


I ran it and it printed:

Code Block
DEBUG set
_DEBUG clear


I then switched the Run action of the scheme to use the Release build (rather than Debug) and the program now prints:

Code Block
DEBUG clear
_DEBUG clear


So, out of the box, Xcode seems to be working as expected. To debug this further you’ll need to look at the tools version you’re using, what frameworks you include, what your project settings are, and so on.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Thank you Quinn for your response.

I put #pragma GCC warning within #ifdef _DEBUG and I received the message saying "_DEBUG defined". Ofcourse, it then goes on to give file not found for crtdbg.h which is not available on Mac.

This is very strange since the same project compiles properly on 9.3.

#ifdef _DEBUG
#pragma GCC warning "_DEBUG defined"
#include <crtdbg.h>
#endif

This is very strange since the same project compiles properly on 9.3.

Right. It’s probably bringing in a header that sets up _DEBUG in some way. That’s unlikely to be an Apple header (I search the macOS SDK and there are no ‘writes’ to _DEBUG) but it’s hard to be sure without testing your specific project.

The first thing I recommend is that you try repeating my test. I expect you’ll get the same results but, if you don’t, that’ll tell us that the problem is associated to your setup rather than your project (which would be weird, but I’ve seen weirder).

After that it’s just a small question of debugging your project (-: I usually use Product > Perform Action > Preprocess for this sort of debugging.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Update
It seems only some files are having this issue. So, you are right...it seems to be related to the project.

Thank you for your input.

Musten
_DEBUG vs DEBUG Preprocessor Macro
 
 
Q