DLang Notes and Examples
← prev | next →     Top-level ToC     /built-in-types.html     (printable version)
  • void (no type)
  • bool (true, false)
  • byte, ubyte, short (16-bit), ushort, int (32-bit), uint, long (64-bit), ulong
  • float (32-bit), double (64-bit), real (largest native precision for this hw)
  • char (8-bit), wchar (16-bit), dchar (32-bit)

You can get the type of anything via typeid(foo).

1 Literals

auto i = 3;    // int
auto x = 1.2;  // double
2e3       // is a double (2000.0)
2_000_000 // can use underscores
0xff == 0x00_ff == 0x00ff == 0x0000_00ff
0b1000_0000
1000u     // for an unsigned int
1000uL    // for an unsigned long (must be capital ell)
'a'       // is a char (8 bits)
'β'       // (U+03b2) is a wchar (16 bits)
'𝄏'       // (U+1d10f) is a dchar (32 bits)

Note, ints wrap around:

byte i = 126;
i++;  //  127
i++;  // -128

ubyte j = 255;
j++; // Now j is 0.

2 Conversions

  • no implicit narrowing conversions
  • going from uint to int is not considered narrowing
  • no implicit conversion from floating point to integer
int  i = 4;
byte j = 2;
auto k = i + j; // promoted to int

Casts look like:

int i = cast(int)x;  // truncates

3 Aliases

Type aliases look like:

alias MyInt = int;
MyInt i = 5;
typeid(i); // int

but not that MyInt is only a synonym for int. If the compiler has a problem with i, it will refer to int, not MyInt.