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 DataTypesExample/D2

Show
Ignore:
Author:
Andrej08 (IP: 78.2.19.175)
Timestamp:
09/03/10 22:55:54 (14 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DataTypesExample/D2

    v0 v1  
     1= Data Types = 
     2 
     3''Part of'' TutorialFundamentals 
     4 
     5== Description == 
     6 
     7Shows how the `sizeof`, `min`, and `max` properties can reveal the size and possible minimum/maximum values of the data types. 
     8 
     9 
     10== Example == 
     11 
     12{{{ 
     13#!d 
     14import std.stdio; 
     15 
     16void main()  
     17{ 
     18    // Print out information about integer types 
     19    writefln("(%d) bool    min: %20d  max: %20d",    bool.sizeof,   bool.min,   bool.max);   
     20    writefln("(%d) ubyte   min: %20d  max: %20d",   ubyte.sizeof,  ubyte.min,  ubyte.max);   
     21    writefln("(%d) ushort  min: %20d  max: %20d",  ushort.sizeof, ushort.min, ushort.max);   
     22    writefln("(%d) uint    min: %20d  max: %20d",    uint.sizeof,   uint.min,   uint.max);   
     23    writefln("(%d) ulong   min: %20d  max: %20d\n", ulong.sizeof,  ulong.min,  ulong.max);     
     24     
     25    writefln("(%d) byte    min: %20d  max: %20d",    byte.sizeof,  byte.min,  byte.max);   
     26    writefln("(%d) short   min: %20d  max: %20d",   short.sizeof, short.min, short.max);     
     27    writefln("(%d) int     min: %20d  max: %20d",     int.sizeof,   int.min,   int.max);     
     28    writefln("(%d) long    min: %20d  max: %20d\n",  long.sizeof,  long.min,  long.max);     
     29 
     30    // Show information about floating-point types... 
     31    writefln("(%d) float\t(%d) double\t(%d) real", float.sizeof,  double.sizeof,  real.sizeof); 
     32 
     33    // Show information about character types... 
     34    writefln("(%d) char\t(%d) wchar\t(%d) dchar", char.sizeof, wchar.sizeof, dchar.sizeof); 
     35} 
     36}}} 
     37 
     38== Output == 
     39 
     40{{{ 
     41(1) bool    min:                    0  max:                    1 
     42(1) ubyte   min:                    0  max:                  255 
     43(2) ushort  min:                    0  max:                65535 
     44(4) uint    min:                    0  max:           4294967295 
     45(8) ulong   min:                    0  max: 18446744073709551615 
     46 
     47(1) byte    min:                 -128  max:                  127 
     48(2) short   min:               -32768  max:                32767 
     49(4) int     min:          -2147483648  max:           2147483647 
     50(8) long    min: -9223372036854775808  max:  9223372036854775807 
     51 
     52(4) float       (8) double      (10) real 
     53(1) char        (2) wchar       (4) dchar 
     54}}} 
     55 
     56== More Information == 
     57 
     58For more information refer to the official list of D2 types in the [http://www.digitalmars.com/d/2.0/type.html D2 Specification]. 
     59 
     60 
     61== Source == 
     62 
     63Based on [http://jcc_7.tripod.com/d/tutor/types.html types.html] by jcc7.