Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes from Version 1 of CompileTimeBuiltInVersionsExample

Show
Ignore:
Author:
jcc7 (IP: 192.149.244.9)
Timestamp:
12/13/06 22:15:38 (17 years ago)
Comment:

added example

Legend:

Unmodified
Added
Removed
Modified
  • CompileTimeBuiltInVersionsExample

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