Skip to content

Commit a38a660

Browse files
authored
Merge pull request #2115 from WalterBright/type-touchup
type.dd: minor touchup merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
2 parents 04fe5d0 + 5e030f5 commit a38a660

File tree

1 file changed

+40
-43
lines changed

1 file changed

+40
-43
lines changed

spec/type.dd

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,30 @@ $(SPEC_S Types,
44

55
$(HEADERNAV_TOC)
66

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+
715
$(H2 $(LEGACY_LNAME2 Basic Data Types, basic-data-types, Basic Data Types))
816

917
$(TABLE_3COLS Basic Data Types,
1018
$(THEAD Keyword, Default Initializer ($(D .init)), Description)
1119
$(TROW $(D void), $(D -), no type)
1220
$(TROW $(D bool), $(D false), boolean value)
1321
$(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)
1523
$(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)
1725
$(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)
1927
$(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)
2129
$(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))
2331
$(TROW $(D float), $(D float.nan), 32 bit floating point)
2432
$(TROW $(D double), $(D double.nan), 64 bit floating point)
2533
$(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))
3038
$(TROW $(D cfloat), $(D float.nan+float.nan*1.0i), a complex number of two float values)
3139
$(TROW $(D cdouble), $(D double.nan+double.nan*1.0i), complex double)
3240
$(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))
3644
)
3745

3846
$(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)
5058
$(H2 $(LEGACY_LNAME2 User Defined Types, user-defined-types, User-Defined Types))
5159

5260
$(UL
53-
$(LI alias)
5461
$(LI enum)
5562
$(LI struct)
5663
$(LI union)
@@ -68,8 +75,9 @@ enum E : T { ... } // T is the base type of E
6875

6976
$(H2 $(LEGACY_LNAME2 Pointer Conversions, pointer-conversions, Pointer Conversions))
7077

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
7381
allocated by the garbage collector.
7482
)
7583

@@ -151,14 +159,14 @@ $(H2 $(LEGACY_LNAME2 Usual Arithmetic Conversions, usual-arithmetic-conversions,
151159
)
152160

153161
$(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`.)
156164

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`.)
159167

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`.)
162170

163171
$(LI Else the integer promotions are done on each operand,
164172
followed by:
@@ -196,22 +204,15 @@ $(H2 $(LEGACY_LNAME2 Usual Arithmetic Conversions, usual-arithmetic-conversions,
196204
promotion. For example:)
197205

198206
---
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
203211
---
204212

205213
$(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
215216
cannot be implicitly converted to imaginary floating
216217
point types.
217218
)
@@ -235,25 +236,16 @@ pointers or references.)
235236

236237
$(H2 $(LNAME2 delegates, Delegates))
237238

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
240240
object reference and a pointer to a non-static member function, or a pointer to
241241
a closure and a pointer to a nested function. The object reference forms the
242242
`this` pointer when the function is called.)
243243

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:)
247245

248246
-------------------
249247
int function(int) fp; // fp is pointer to a function
250248
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
257249
-------------------
258250

259251
$(P A delegate is initialized analogously to function pointers:
@@ -262,7 +254,6 @@ int (*fp)(int); // fp is pointer to a function
262254
-------------------
263255
int func(int);
264256
fp = &func; // fp points to func
265-
266257
class OB
267258
{
268259
int member(int);
@@ -300,14 +291,20 @@ auto c = new C(); // create an instance of C
300291
mfp(c, 1); // and call c.foo(1)
301292
---
302293

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+
303300
$(H2 $(LNAME2 size_t, $(D size_t)))
304301

305302
$(P $(D size_t) is an alias to one of the unsigned integral basic types,
306303
and represents a type that is large enough to represent an offset into
307304
all addressible memory.)
308305

309306
$(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).)
311308

312309
$(SPEC_SUBNAV_PREV_NEXT declaration, Declarations, property, Properties)
313310
)

0 commit comments

Comments
 (0)