Closed noodlecollie closed 6 years ago
_DEBUG macro is a one of many leftovers from original Xash3D code. Yes, for compability it can be defined in such way. I don't know though about MinGW.
IMHO, such macro shouldn't be used in code(except assertions, maybe). Otherwise, it may lead to difference between Release and Debug builds.
NDEBUG though, isn't guaranteed to be defined. I remember, that this macro isn't defined by compiler itself, instead it always done on buildsystem side. And Android.mk does not define it sometimes.
Maybe _DEBUG can be set in CMake/Android.mk directly.
I was planning to use it so that certain bits of my code deliberately won't be available in release builds. I will look into defining it in the CMake files though.
In addition, I've discovered that the DEBUG_BREAK
macro isn't set up for Mac. The following pages are how I got it to work for my own code:
https://developer.apple.com/library/content/qa/qa1361/_index.html https://stackoverflow.com/questions/37299/xcode-equivalent-of-asm-int-3-debugbreak-halt
both _DEBUG and NDEBUG are used as preprocessor commands in msvc to distinguish between release and debug builds, but no the compiler itself has no notion of these. DEBUGBREAK is however supported on the later versions of msvc, i think it was supported from msvc2010 and forward. The debug and release macros stem back from the quake days because quake used to be built with a DOS version of gcc (djgpp).
I've also noticed that the debugger doesn't break on Linux when errors are thrown, because GDB_BREAK
doesn't seem to be defined. Is this something that should be defined in the CMake files, or in code?
EDIT: Additionally, StackOverflow says the following with respect to NDEBUG
:
CMake adds
-DNDEBUG
to theCMAKE_C_FLAGS_{RELEASE, MINSIZEREL}
by default. So, you can use#ifndef NDEBUG
.
Closing this - it's fixed in the above pull request.
#ifdef _DEBUG
code doesn't seem to be included for me when I build for Mac in debug mode. I haven't had a chance to check it with Linux yet, but I suspect the issue is the same.I've read up on how Cmake handles the debug configuration for makefiles, and apparently passing
-DCMAKE_BUILD_TYPE=Debug
means thatNDEBUG
is then not defined. My current workaround, therefore, is to add the following to somewhere likecommon.h
:Is this correct, or is there a recommended way?