O'Reilly logo

Learning D by Michael Parker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Conditional compilation

The C preprocessor makes it possible to conditionally compile certain blocks of code using #define and related directives. Once again, D achieves similar results using built-in compile-time statements, such as version, debug, and static if.

The version condition

A version condition is used to instruct the compiler to generate code for anything in the version block only if the specific condition is defined. Here's an example:

version(Windows)
  pragma(msg, "We are compiling on Windows.");
else version(OSX)
  pragma(msg, "We are compiling on a Mac OS X system.");
else version(Posix)
  pragma(msg, "We are compiling on a Posix system.");

This example uses the predefined versions Windows, OSX, and Posix. Swap the order of the Posix and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required