@@ -4,22 +4,30 @@ $(SPEC_S Types,
4
4
5
5
$(HEADERNAV_TOC)
6
6
7
+ $(P D is statically typed. Every expression has a type. Types constrain the values
8
+ an expression can hold, and determine the semantics of operations on those values.
9
+ )
10
+
11
+ $(P Basic data types are leaf types. Derived data types build on leaf types. User defined
12
+ types are aggregates of basic and derived types.
13
+ )
14
+
7
15
$(H2 $(LEGACY_LNAME2 Basic Data Types, basic-data-types, Basic Data Types))
8
16
9
17
$(TABLE_3COLS Basic Data Types,
10
18
$(THEAD Keyword, Default Initializer ($(D .init)), Description)
11
19
$(TROW $(D void), $(D -), no type)
12
20
$(TROW $(D bool), $(D false), boolean value)
13
21
$(TROW $(D byte), $(D 0), signed 8 bits)
14
- $(TROW $(D ubyte), $(D 0 ), unsigned 8 bits)
22
+ $(TROW $(D ubyte), $(D 0u ), unsigned 8 bits)
15
23
$(TROW $(D short), $(D 0), signed 16 bits)
16
- $(TROW $(D ushort), $(D 0 ), unsigned 16 bits)
24
+ $(TROW $(D ushort), $(D 0u ), unsigned 16 bits)
17
25
$(TROW $(D int), $(D 0), signed 32 bits)
18
- $(TROW $(D uint), $(D 0 ), unsigned 32 bits)
26
+ $(TROW $(D uint), $(D 0u ), unsigned 32 bits)
19
27
$(TROW $(D long), $(D 0L), signed 64 bits)
20
- $(TROW $(D ulong), $(D 0L ), unsigned 64 bits)
28
+ $(TROW $(D ulong), $(D 0uL ), unsigned 64 bits)
21
29
$(TROW $(D cent), $(D 0), signed 128 bits (reserved for future use))
22
- $(TROW $(D ucent), $(D 0 ), unsigned 128 bits (reserved for future use))
30
+ $(TROW $(D ucent), $(D 0u ), unsigned 128 bits (reserved for future use))
23
31
$(TROW $(D float), $(D float.nan), 32 bit floating point)
24
32
$(TROW $(D double), $(D double.nan), 64 bit floating point)
25
33
$(TROW $(D real), $(D real.nan), largest FP size implemented in
@@ -30,9 +38,9 @@ $(H2 $(LEGACY_LNAME2 Basic Data Types, basic-data-types, Basic Data Types))
30
38
$(TROW $(D cfloat), $(D float.nan+float.nan*1.0i), a complex number of two float values)
31
39
$(TROW $(D cdouble), $(D double.nan+double.nan*1.0i), complex double)
32
40
$(TROW $(D creal), $(D real.nan+real.nan*1.0i), complex real)
33
- $(TROW $(D char), $(D 0xFF ), unsigned 8 bit (UTF-8 code unit))
34
- $(TROW $(D wchar), $(D 0xFFFF ), unsigned 16 bit (UTF-16 code unit))
35
- $(TROW $(D dchar), $(D 0x0000FFFF ), unsigned 32 bit (UTF-32 code unit))
41
+ $(TROW $(D char), $(D 'xFF' ), unsigned 8 bit (UTF-8 code unit))
42
+ $(TROW $(D wchar), $(D 'uFFFF' ), unsigned 16 bit (UTF-16 code unit))
43
+ $(TROW $(D dchar), $(D 'U0000FFFF' ), unsigned 32 bit (UTF-32 code unit))
36
44
)
37
45
38
46
$(H2 $(LEGACY_LNAME2 Derived Data Types, derived-data-types, Derived Data Types))
@@ -50,7 +58,6 @@ $(H2 $(LEGACY_LNAME2 Derived Data Types, derived-data-types, Derived Data Types)
50
58
$(H2 $(LEGACY_LNAME2 User Defined Types, user-defined-types, User-Defined Types))
51
59
52
60
$(UL
53
- $(LI alias)
54
61
$(LI enum)
55
62
$(LI struct)
56
63
$(LI union)
@@ -68,8 +75,9 @@ enum E : T { ... } // T is the base type of E
68
75
69
76
$(H2 $(LEGACY_LNAME2 Pointer Conversions, pointer-conversions, Pointer Conversions))
70
77
71
- $(P Casting pointers to non-pointers and vice versa is allowed in D,
72
- however, do not do this for any pointers that point to data
78
+ $(P Casting pointers to non-pointers and vice versa is allowed.)
79
+
80
+ $(BEST_PRACTICE do not do this for any pointers that point to data
73
81
allocated by the garbage collector.
74
82
)
75
83
@@ -151,14 +159,14 @@ $(H2 $(LEGACY_LNAME2 Usual Arithmetic Conversions, usual-arithmetic-conversions,
151
159
)
152
160
153
161
$(OL
154
- $(LI If either operand is real, the other operand is
155
- converted to real.)
162
+ $(LI If either operand is ` real` , the other operand is
163
+ converted to ` real` .)
156
164
157
- $(LI Else if either operand is double, the other operand is
158
- converted to double.)
165
+ $(LI Else if either operand is ` double` , the other operand is
166
+ converted to ` double` .)
159
167
160
- $(LI Else if either operand is float, the other operand is
161
- converted to float.)
168
+ $(LI Else if either operand is ` float` , the other operand is
169
+ converted to ` float` .)
162
170
163
171
$(LI Else the integer promotions are done on each operand,
164
172
followed by:
@@ -196,22 +204,15 @@ $(H2 $(LEGACY_LNAME2 Usual Arithmetic Conversions, usual-arithmetic-conversions,
196
204
promotion. For example:)
197
205
198
206
---
199
- ubyte u1 = cast(byte) -1; // error, -1 cannot be represented in a ubyte
200
- ushort u2 = cast(short) -1; // error, -1 cannot be represented in a ushort
201
- uint u3 = cast( int)-1; // ok, -1 can be represented in a uint
202
- ulong u4 = cast( long)-1 ; // ok, -1 can be represented in a ulong
207
+ ubyte u1 = -1; // error, -1 cannot be represented in a ubyte
208
+ ushort u2 = -1; // error, -1 cannot be represented in a ushort
209
+ uint u3 = int(-1); // ok, -1 can be represented in a uint
210
+ ulong u4 = long(-1) ; // ok, -1 can be represented in a ulong
203
211
---
204
212
205
213
$(P Floating point types cannot be implicitly converted to
206
- integral types.
207
- )
208
-
209
- $(P Complex floating point types cannot be implicitly converted
210
- to non-complex floating point types.
211
- )
212
-
213
- $(P Imaginary floating point types cannot be implicitly converted to
214
- float, double, or real types. Float, double, or real types
214
+ integral types. Complex or imaginary floating point types cannot be implicitly converted
215
+ to non-complex floating point types. Non-complex floating point types
215
216
cannot be implicitly converted to imaginary floating
216
217
point types.
217
218
)
@@ -235,25 +236,16 @@ pointers or references.)
235
236
236
237
$(H2 $(LNAME2 delegates, Delegates))
237
238
238
- $(P There are no pointers-to-members in D, but a more useful concept called $(I
239
- delegates) is supported. Delegates are an aggregate of two pieces of data: an
239
+ $(P Delegates are an aggregate of two pieces of data: an
240
240
object reference and a pointer to a non-static member function, or a pointer to
241
241
a closure and a pointer to a nested function. The object reference forms the
242
242
`this` pointer when the function is called.)
243
243
244
- $(P Delegates are declared similarly to function pointers, except that the
245
- keyword $(D delegate) takes the place of (*), and the identifier occurs
246
- afterwards:)
244
+ $(P Delegates are declared similarly to function pointers:)
247
245
248
246
-------------------
249
247
int function(int) fp; // fp is pointer to a function
250
248
int delegate(int) dg; // dg is a delegate to a function
251
- -------------------
252
-
253
- $(P The C style syntax for declaring pointers to functions is deprecated:)
254
-
255
- -------------------
256
- int (*fp)(int); // fp is pointer to a function
257
249
-------------------
258
250
259
251
$(P A delegate is initialized analogously to function pointers:
@@ -262,7 +254,6 @@ int (*fp)(int); // fp is pointer to a function
262
254
-------------------
263
255
int func(int);
264
256
fp = &func; // fp points to func
265
-
266
257
class OB
267
258
{
268
259
int member(int);
@@ -300,14 +291,20 @@ auto c = new C(); // create an instance of C
300
291
mfp(c, 1); // and call c.foo(1)
301
292
---
302
293
294
+ $(P The C style syntax for declaring pointers to functions is deprecated:)
295
+
296
+ -------------------
297
+ int (*fp)(int); // fp is pointer to a function
298
+ -------------------
299
+
303
300
$(H2 $(LNAME2 size_t, $(D size_t)))
304
301
305
302
$(P $(D size_t) is an alias to one of the unsigned integral basic types,
306
303
and represents a type that is large enough to represent an offset into
307
304
all addressible memory.)
308
305
309
306
$(H2 $(LNAME2 ptrdiff_t, $(D ptrdiff_t)))
310
- $(P $(D ptrdiff_t) is an alias to the signed basic type the same size as $(D size_t).)
307
+ $(P $(D ptrdiff_t) is an alias to the signed integral basic type the same size as $(D size_t).)
311
308
312
309
$(SPEC_SUBNAV_PREV_NEXT declaration, Declarations, property, Properties)
313
310
)
0 commit comments