Preprocessor definition for debug code

Get help with programming issues.

Moderator: PPS-Leaders

Post Reply
muemart
Noxonian Qulomks
Posts: 28
Joined: Fri Mar 28, 2014 1:10 pm

Preprocessor definition for debug code

Post by muemart » Mon Feb 09, 2015 5:23 pm

Is there a standard preprocessor definition for debug code? I spotted some #ifndef NDEBUGs and #ifdef _DEBUGs, but I don't know if they are platform independent and which one I should use. I'm writing (actually, I'm done) some sort of stack trace for the xml/lua loader, which isn't really necessary for release builds.

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Re: Preprocessor definition for debug code

Post by x3n » Tue Feb 10, 2015 10:08 pm

Two answers on this question:

1) NDEBUG (for release) and _DEBUG (for debug) both work. They are defined as compiler flags for both MSVC and GCC builds. For example, NDEBUG is used in util/OrxAssert.h

2) Don't use it unless you have really good reasons to disable/enable a feature under certain build conditions. Every #if makes the code harder to test because it means that code that runs in one environment may fail in another. If your code doesn't severly compromise the release build I suggest to enable it for both build settings.
Fabian 'x3n' Landau, Orxonox developer

muemart
Noxonian Qulomks
Posts: 28
Joined: Fri Mar 28, 2014 1:10 pm

Re: Preprocessor definition for debug code

Post by muemart » Wed Feb 11, 2015 9:09 am

I'll leave the defines out, then. It only needs a few megabytes of memory (strongly depends on how big the file is), and is probably lightning fast compared to the lua code anyway.

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Re: Preprocessor definition for debug code

Post by x3n » Wed Feb 11, 2015 9:14 pm

people that create mainly content (and no code) for Orxonox may use a release build, so I think it's a good thing to enable this feature for all builds.
Fabian 'x3n' Landau, Orxonox developer

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest