Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile out code for release build in D

Tags:

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?

like image 523
JRM Avatar asked Jul 06 '10 22:07

JRM


People also ask

How to Release build in Visual Studio?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).

What is difference between debug and Release build?

Debug Mode: When we are developing the application. Release Mode: When we are going to production mode or deploying the application to the server. Debug Mode: The debug mode code is not optimized. Release Mode: The release mode code is optimized.

What is debug and Release in Visual Studio?

By default, Debug includes debug information in the compiled files (allowing easy debugging) while Release usually has optimizations enabled. As far as conditional compilation goes, they each define different symbols that can be checked in your program, but they are language-specific macros.

What is the difference between Release mode and debug mode in Visual Studio?

The Debug configuration of your program is compiled with full symbolic debug information which help the debugger figure out where it is in the source code. Is Release mode is faster than Debug mode ? The Release mode enables optimizations and generates without any debug data, so it is fully optimized. .


1 Answers

There is a global notion of debug. Just write:

debug {
    ... code ...
}
like image 153
Andrei Alexandrescu Avatar answered Sep 23 '22 02:09

Andrei Alexandrescu