Data Types and Sizes
D provides fundamental data types for integers and floating-point constants. Arithmetic can be performed only on integers in D programs. Floating-point constants can be used to initialize data structures, but you cannot perform floating-point arithmetic in D. D provides a 32-bit and 64-bit data model for use in writing programs. The data model used when executing your program is the native data model associated with the active operating system kernel. You can use the isainfo -b
command to determine the native data model of your system.
The names of the integer types and their sizes in each of the two data models are shown in the following table. Integers are always represented in two's complement form in the native byte-encoding order of your system.
Table 2-2 D Integer Data Types
Type | 32-bit Size | 64-bit Size |
---|---|---|
|
1 byte |
1 byte |
|
2 bytes |
2 bytes |
|
4 bytes |
4 bytes |
|
4 bytes |
8 bytes |
|
8 bytes |
8 bytes |
Integer types may be prefixed with the signed or unsigned qualifier. If no sign qualifier is present, the type is assumed to be signed. The D compiler also provides the type aliases listed in the following table.
Table 2-3 D Integer Type Aliases
Type | Description |
---|---|
|
1 byte signed integer |
|
2 byte signed integer |
|
4 byte signed integer |
|
8 byte signed integer |
|
Signed integer of size equal to a pointer |
|
1 byte unsigned integer |
|
2 byte unsigned integer |
|
4 byte unsigned integer |
|
8 byte unsigned integer |
|
Unsigned integer of size equal to a pointer |
These type aliases are equivalent to using the name of the corresponding base type in the Table 2-2 and are appropriately defined for each data model. For example, the type name uint8_t
is an alias for the type unsigned char
. For more information about how to define your own type aliases, see Type and Constant Definitions in DTrace.
Note:
The predefined type aliases cannot be used in files included by the preprocessor.D provides floating-point types for compatibility with ANSI-C declarations and types. Floating-point operators are not supported in D, but floating-point data objects can be traced and formatted using the printf
() function. You can use the floating-point types listed in the following table.
Table 2-4 D Floating-Point Data Types
Type | 32-bit Size | 64-bit Size |
---|---|---|
|
4 bytes |
4 bytes |
|
8 bytes |
8 bytes |
|
16 bytes |
16 bytes |
D also provides the special type string to represent ASCII strings. Strings are discussed in more detail in Strings in DTrace.