Search code examples
d

Compile out code for release build in D


Is there any mechanism in D (D2) to force code to be compiled out during a release build?

In C, you might have something like

#ifndef NDEBUG
/*Something that will only run in a debug build*/
#endif

I know that D has

debug(mymodule) {
   //Do something
}

But this requires the user to pass -debug for each module to enable it.

I'm looking for a global mechanism that will always run the code in a normal build but compile it out when you pass the -release flag. I know some built-ins have this ability (e.g. assert), but is there any way for user code to do it too?


Solution

  • There is a global notion of debug. Just write:

    debug {
        ... code ...
    }