version(tag) and version(level)
Get introduced to the version feature of conditional compilation in D.
We'll cover the following
version
is similar to debug
and is used in the same way:
version(testRelease) /* ... an expression ... */;
version(schoolRelease) {
/* ... expressions that are related to the version of
* this program that is presumably shipped to schools ... */
} else {
// ... code compiled otherwise ...
}
version(1) aVariable = 5;
version(2) {
// ... a feature of version 2 ...
}
The else
clause is optional.
Although version
works essentially the same as debug
, having separate
keywords helps distinguish their unrelated uses.
As with debug
, more than one version can be enabled:
$ dmd deneme.d -w -version=record -version=precise_calculation
There are many predefined version tags, the complete list of which is available at the conditional compilation specification. The following short list is just a sampling:
Get hands-on with 1400+ tech skills courses.