www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DFLAGS: debug vs release

Seems like "-debug" and "-release" has
reaped another fresh batch of victims...

It's rather natural to think that these
two are somewhat related (and opposites)

They are not.


The -debug flag, "compile in debug code" (says
http://www.digitalmars.com/d/dcompiler.html)
is just a special conditional D "version":

Debug Statement
http://www.digitalmars.com/d/version.html#debug
 Two versions of programs are commonly built, a release build and a debug
 build. The debug build commonly includes extra error checking code, test
 harnesses, pretty-printing code, etc. The debug statement conditionally
 compiles in its statement body. It is D's way of what in C is done with
 #ifdef DEBUG / #endif pairs.
However, the -release flag is all about *Contracts*: "means not generating code for contracts and asserts" (as http://www.digitalmars.com/d/dcompiler.html says) DMD 0.118
     if (global.params.release)
     {	global.params.useInvariants = 0;
 	global.params.useIn = 0;
 	global.params.useOut = 0;
 	global.params.useAssert = 0;
 	global.params.useArrayBounds = 0;
 	global.params.useSwitchError = 0;
     }
Which means that if you do *not* add -release, you get all contracts in place and they *will* throw AssertError and ArrayBoundsError and SwitchError (some are even lobbying for AA: MissingKeyError!) And these Exceptions, (if uncaught by a catch() {}) is what is causing the program to "end abnormally". This has *nothing* to do with -debug, which means that all code within "debug { }" should be enabled... To build a "release" version of the code, you instead just *not* give the -debug flag and they are stripped. Advanced note: you can also debug just certain sections, by using the debug(FOO) {} form and the -debug=FOO flag. As mentioned before: The DFLAG of "-release" is horribly badly named now, and would be much better off as "-nocontracts" or something ? (which reminds that I should rename my own "phobos-debug" package and library as "phobos-contracts" now instead...) Like Walter said: [digitalmars.D/15830]
The original idea behind -release was to not require the DMD programmer to
learn a bunch of arcane weird switches (look at any C++ compiler!), there'd
be a switch that would make it "just work".

Looks like I failed  :-( 
This, like D compiler warnings, might be something to back up on ? Having individual flags for each of contracts, assertions, arraybounds and switcherror... (already, -unittest needs to turn the assertions on) --anders
Mar 16 2005