Skip to main content
gamedev.net
🔒 Locked

Configuration specific code

Started by The C modest god Oct 28, 2005 at 6:13 AM 5 replies 500+ views
Original Post
The C modest god
The C modest god
I want an if statement that will occur only if I compile my program in debug configuration and wont occur if I compile in release configuration. How do I achieve that?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
nmi
nmi
Which language ?

When using C/C++ you can write:
#ifdef DEBUG// your debug statements#endif

and make sure that you define DEBUG when in debug mode, i.e. passing -DDEBUG to your compiler.
haegarr
haegarr
In principal I agree w/ nmi, but I've read somewhere that MSC uses _DEBUG instead of DEBUG. So there may be little variations in dependence of the compiler in use. (E.g. gcc uses DEBUG). For portability it would be best to unify these stuff in a prerequisites header file if possible.
joanusdmentia
joanusdmentia
Quote:
Original post by haegarr
In principal I agree w/ nmi, but I've read somewhere that MSC uses _DEBUG instead of DEBUG. So there may be little variations in dependence of the compiler in use. (E.g. gcc uses DEBUG). For portability it would be best to unify these stuff in a prerequisites header file if possible.


Note that NMI mentioned to make sure he defines DEBUG. MSVC uses _DEBUG as the default, but you can change this very easily by modifying the defined variables in the preprocessor properties.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
haegarr
haegarr
@joanusdmentia: Right you are.

However, it seems senseful to me to couple the inclusion/exclusion of the if clause as is requested in the original posting to the standard flags, instead of overhanding an own flag (what of course also can make sense). So I've suggested a prerequisites header file to overcome protability problems by unifying the possible "standard" compiler flags to one to be used throughout the sources.
joanusdmentia
joanusdmentia
Quote:
Original post by haegarr
However, it seems senseful to me to couple the inclusion/exclusion of the if clause as is requested in the original posting to the standard flags, instead of overhanding an own flag (what of course also can make sense). So I've suggested a prerequisites header file to overcome protability problems by unifying the possible "standard" compiler flags to one to be used throughout the sources.


I find that a prerequisites header file of sorts to be more trouble than it's worth. You more often than not start loading it with all sorts of things that really shouldn't be there and makes your code dependant on an essentially unrelated header.

Not only that, but your prerequisites file needs to try and account for all the different 'standard' defines for different compilers to try and guess if you're running a debug build or not (admittadly there's prob only the 2 variations). It's far simpler to just say 'define this in your project for debug builds'.

Having said that, if you're only using the 1 compiler it doesn't really matter [smile]
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
haegarr
haegarr
Quote:
Original post by joanusdmentia
You more often than not start loading it with all sorts of things that really shouldn't be there and makes your code dependant on an essentially unrelated header.

Of cource, one could do wrong things anywhere, and hence also in a prerequisites header. The inclusion of other header files (as you mentioned as an example) is such a trap, right you are.

I personally use a prerequisites header, including nothing more than (which is actually used by every compile unit). All the other stuff is pre-processor related: Determining the OS, debug/release stuff, compiler and compiler version, and the dynamic lib export stuff. Not all but most of this is used almost everywhere.

Quote:
Original post by joanusdmentia
Not only that, but your prerequisites file needs to try and account for all the different 'standard' defines for different compilers to try and guess if you're running a debug build or not (admittadly there's prob only the 2 variations). It's far simpler to just say 'define this in your project for debug builds'.

Ok. There's nothing to say against this point of view. I'm using a scheme of assertions named "design by contract" (Meyer) that is to be switched on/off independently from debug/release mode. You see, I'm also already following this way ;-)

After all, its a question of personal preferences, but _if_ used, a prerequisites header should be designed to hold essentials only.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.