D provides a number of basic types which always have the same
size regardless of the platform - the only exception
real type which provides the highest possible floating point
precision. There is no difference
between the size of an integer regardless of whether the application
is compiled for 32-bit or 64-bit systems.
|>= 64-bit (generally 64-bit, but 80-bit on Intel x86 32-bit)
u denotes unsigned types.
char translates to
wchar is used in UTF-16 strings and
in UTF-32 strings.
A conversion between variables of different types is only
allowed by the compiler if no precision is lost. However,
a conversion between floating point types
float) is allowed.
A conversion to another type may be forced by using the
cast(TYPE) myVar expression. It needs to be used with great care though,
cast expression is allowed to break the type system.
The special keyword
auto creates a variable and infers its
type from the right hand side of the expression.
auto myVar = 7
will deduce the type
myVar. Note that the type is still
set at compile-time and can't be changed - just like with any other
variable with an explicitly given type.
All data types have a property
.init to which they are initialized.
For all integers this is
0 and for floating points it is
nan (not a number).
Integral and floating point types have a
.max property for the highest value
they can represent. Integral types also have a
.min property for the lowest value
they can represent, whereas floating point types have a
which is defined to the smallest representable normalized value that's not 0.
Floating point types also have properties
.dig (number of decimal digits of precisions),
(number of bits in mantissa) and more.
Every type also has a
.stringof property which yields its name as a string.
In D, indexes usually have the alias type
size_t, as it is a type that
is large enough to represent an offset into all addressable memory - this is
uint for 32-bit and
ulong for 64-bit architectures.
assert is an expression which verifies conditions in debug mode and aborts
AssertionError if it fails.
assert(0) is thus used to mark unreachable code.