| 1 | = Compile-Time Built-in Versions = |
---|
| 2 | |
---|
| 3 | ''Part of'' VersioningCategory |
---|
| 4 | |
---|
| 5 | == Description == |
---|
| 6 | |
---|
| 7 | Determine your compile environment at compile time (and even output the results at compile time). |
---|
| 8 | |
---|
| 9 | == Related Example == |
---|
| 10 | |
---|
| 11 | BuiltInVersionsExample |
---|
| 12 | |
---|
| 13 | == Example == |
---|
| 14 | |
---|
| 15 | {{{ |
---|
| 16 | #!d |
---|
| 17 | version(DigitalMars) pragma(msg, "Compiler Vendor: Digital Mars"); |
---|
| 18 | version(linux) pragma(msg, "Operating System: Linux."); |
---|
| 19 | version(Windows) pragma(msg, "Operating System: Microsoft Windows"); |
---|
| 20 | version(Win32) pragma(msg, "Microsoft Windows (32-bit)"); |
---|
| 21 | version(Win64) pragma(msg, "Microsoft Windows (64-bit)"); |
---|
| 22 | |
---|
| 23 | version(Windows) |
---|
| 24 | { |
---|
| 25 | version(Win32) {} |
---|
| 26 | else version(Win64) {} |
---|
| 27 | else pragma(msg, "Microsoft Windows (?-bit)"); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | version(linux) {} |
---|
| 31 | else version(Windows) {} |
---|
| 32 | else pragma(msg, "Operating System: Unknown"); |
---|
| 33 | |
---|
| 34 | version(X86) pragma(msg, "Processor: Intel or AMD 32-bit"); |
---|
| 35 | version(AMD64) pragma(msg, "Processor: AMD 64-bit processor"); |
---|
| 36 | |
---|
| 37 | version(LittleEndian) pragma(msg, "byte order: least significant first"); |
---|
| 38 | version(BigEndian) pragma(msg, "byte order: most significant first"); |
---|
| 39 | |
---|
| 40 | version(LittleEndian) {} |
---|
| 41 | else version(BigEndian) {} |
---|
| 42 | else pragma(msg, "byte order: unknown"); |
---|
| 43 | |
---|
| 44 | version(D_InlineAsm) pragma(msg, "Inline assembler: implemented\n"); |
---|
| 45 | |
---|
| 46 | version(none) pragma(msg, "This code is always disabled.\n"); |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | import std.stdio : writefln; |
---|
| 50 | |
---|
| 51 | void main() |
---|
| 52 | { |
---|
| 53 | writefln("Nothing needs to happen during runtime |
---|
| 54 | since the real work was done during compilation."); |
---|
| 55 | } |
---|
| 56 | }}} |
---|
| 57 | |
---|
| 58 | == Testing == |
---|
| 59 | |
---|
| 60 | Tested with Digital Mars D Compiler v0.177 on Windows 2000. |
---|
| 61 | |
---|
| 62 | == Sample Output == |
---|
| 63 | |
---|
| 64 | (The output will depend on the operating system and architecture that the program is run on.) |
---|
| 65 | |
---|
| 66 | {{{ |
---|
| 67 | Compiler Vendor: Digital Mars |
---|
| 68 | Operating System: Microsoft Windows |
---|
| 69 | Microsoft Windows (32-bit) |
---|
| 70 | Processor: Intel or AMD 32-bit |
---|
| 71 | byte order: least significant first |
---|
| 72 | Inline assembler: implemented |
---|
| 73 | }}} |