-debug and -release

Derek Parnell derek at psych.ward
Sun May 27 15:09:39 PDT 2007


On Sun, 27 May 2007 14:15:13 -0400, lurker wrote:

> What does it mean to compile a file with -debug and -release switches? Like so:
> 
> $ echo "void main() {}" > test.d
> $ dmd -debug -release test.d
> 
> Why the compiler accepts both and doesn't complaint?

The compiler accepts both because they are not opposites of each other,
despite what one may think just knowing the English terms.

"-debug" functionality is almost exactly like the "-version" switch. It
actually has nothing intrinsic to with debugging other than identifying
sections of code as ones in which the author nominates, and thus presumably
intends, to be debugging code. But the code can contain anything at all.
These sections of code are brought into the compilation process in exactly
the same way as sections identified using the version construct. In fact,
one can use "version(XXX){}" and "debug(XXX){}" interchangeably. In other
words ...

   debug(ABC) { ... }

is functionally identical to 

  version(ABC) { ... }

The purpose of using "debug" rather than "version" is just to highlight to
readers of the source code the sections that are intended to be debugging
stuff. There is nothing 'magic' about "-debug".

"-release" controls whether or not built-in and user-defined checks are
excluded from the compilation. If you do not have "-release" the compiler
adds array bounds checking, assert() functionality, invariant blocks in
classes, and in/out blocks in functions. If you use "-release" such
functionality is ignored by the compiler. Presumably the name "release" is
being associated with the desire to remove time consuming run time checks
in a program that has been debugged and is ready now for production
release.

-- 
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell



More information about the Digitalmars-d mailing list