D
程序设计语言
DMD1.0
原英文版权属于
Digital Mars
翻译的大部分文档版权属于
uframer
其中有部分翻译文档版权属于
qiezi
其中有部分翻译文档版权属于
ideage
目录
目录
.....................................................................................................................................................
2
D
程序设计语言概览
.......................................................................................................................
14
什么是
D
语言
?
.........................................................................................................................
15
为什么是
D
?
.........................................................................................................................
15
D
的主要目标
...................................................................................................................
16
从
C/C++
保留而来的特征
...............................................................................................
16
废弃的特征
.......................................................................................................................
17
D
适合于?
.......................................................................................................................
18
D
不适合于?
...................................................................................................................
19
D
的主要特征
...........................................................................................................................
20
面向对象编程
...................................................................................................................
20
生产力
...............................................................................................................................
20
函数
...................................................................................................................................
23
数组
...................................................................................................................................
24
资源管理
...........................................................................................................................
25
性能
...................................................................................................................................
26
可靠性
...............................................................................................................................
26
兼容性
...............................................................................................................................
29
项目管理
...........................................................................................................................
30
示例程序
(sieve.d)
...................................................................................................................
30
词法
...................................................................................................................................................
32
编译的阶段
...............................................................................................................................
32
源码文本
...................................................................................................................................
32
文件尾
.......................................................................................................................................
33
行尾
...........................................................................................................................................
34
空白
...........................................................................................................................................
34
注释
...........................................................................................................................................
34
记号
...........................................................................................................................................
35
标志符
.......................................................................................................................................
37
字符串文字量
...........................................................................................................................
37
字符文字量
...............................................................................................................................
40
整数文字量
...............................................................................................................................
40
浮点数文字量
...........................................................................................................................
42
关键字
.......................................................................................................................................
44
特殊记号
.................................................................................................................................
46
特殊记号序列
...........................................................................................................................
47
模块
...................................................................................................................................................
47
模块的声明
...............................................................................................................................
48
导入声明
...................................................................................................................................
49
作用域和模块
...........................................................................................................................
50
模块作用域运算符
...........................................................................................................
51
静态构造和析构
.......................................................................................................................
51
静态构造的顺序
...............................................................................................................
51
一个模块中静态构造的顺序
...........................................................................................
51
静态析构的顺序
...............................................................................................................
52
声明
...................................................................................................................................................
53
声明语法
...................................................................................................................................
56
类型定义
...................................................................................................................................
57
类型别名
...................................................................................................................................
57
别名声明
...................................................................................................................................
57
typeof ......................................................................................................................................... 59
类型
...................................................................................................................................................
61
基本数据类型
...........................................................................................................................
61
派生数据类型
...........................................................................................................................
62
用户定义数据类型
...................................................................................................................
62
指针转换
...................................................................................................................................
62
隐式转换
...................................................................................................................................
62
整数提升
...........................................................................................................................
63
常用算数转换
...................................................................................................................
63
bool ............................................................................................................................................ 64
委托
...........................................................................................................................................
64
属性
...................................................................................................................................................
66
所有类型的属性
.......................................................................................................................
66
整数类型的属性
.......................................................................................................................
66
浮点类型的属性
.......................................................................................................................
67
浮点型别的属性
.......................................................................................................................
67
.init
属性
....................................................................................................................................
68
类和结构的属性
...............................................................................................................
69
特征
(Attributes)
................................................................................................................................
70
链接特征
...................................................................................................................................
71
对齐特征
...................................................................................................................................
72
废弃特征
...................................................................................................................................
73
保护特征
...................................................................................................................................
73
Const
特征
.................................................................................................................................
74
Override
特征
............................................................................................................................
74
Static
特征
.................................................................................................................................
75
Auto
特征
..................................................................................................................................
75
抽象特征
...................................................................................................................................
76
编译器指令
(pragma)
........................................................................................................................
77
预定义
Pragma
.........................................................................................................................
77
特定于产品提供商的
Pragma
................................................................................................
78
表达式
...............................................................................................................................................
79
求值顺序
...................................................................................................................................
86
表达式
.......................................................................................................................................
86
赋值表达式
...............................................................................................................................
86
赋值运算符表达式
...........................................................................................................
87
条件表达式
...............................................................................................................................
87
OrOr
表达式
.............................................................................................................................
88
AndAnd
表达式
........................................................................................................................
88
按位表达式
...............................................................................................................................
88
Or
表达式
..........................................................................................................................
89
Xor
表达式
........................................................................................................................
89
And
表达式
.......................................................................................................................
89
相等表达式
...............................................................................................................................
89
同一表达式
...............................................................................................................................
90
关系表达式
...............................................................................................................................
90
整数比较
...........................................................................................................................
91
浮点数比较
.......................................................................................................................
92
In
表达式
...................................................................................................................................
93
移位表达式
...............................................................................................................................
93
和表达式
...................................................................................................................................
93
积表达式
...................................................................................................................................
94
一元表达式
...............................................................................................................................
95
New
表达式
......................................................................................................................
95
Delete
表达式
....................................................................................................................
96
转型表达式
.......................................................................................................................
96
后缀表达式
...............................................................................................................................
97
索引表达式
...............................................................................................................................
98
切片表达式
...............................................................................................................................
98
基本表达式
...............................................................................................................................
98
.
标志符
..............................................................................................................................
99
this ..................................................................................................................................... 99
super ................................................................................................................................ 100
null ................................................................................................................................... 100
true, false ......................................................................................................................... 100
字符文字量
.....................................................................................................................
100
数组文字量
.....................................................................................................................
100
函数文字量
.....................................................................................................................
101
断言表达式
.....................................................................................................................
103
Typeid
表达式
.................................................................................................................
103
Is
表达式
.................................................................................................................................
103
语句
.................................................................................................................................................
108
标号语句
.................................................................................................................................
108
语句块
.....................................................................................................................................
109
表达式语句
.............................................................................................................................
110
声明语句
.................................................................................................................................
110
If
语句
......................................................................................................................................
111
While
语句
..............................................................................................................................
111
Do-While
语句
........................................................................................................................
112
For
语句
...................................................................................................................................
112
Foreach
语句
...........................................................................................................................
114
Switch
语句
.............................................................................................................................
118
Continue
语句
.........................................................................................................................
120
Break
语句
..............................................................................................................................
121
Return
语句
.............................................................................................................................
121
Goto
语句
................................................................................................................................
122
With
语句
................................................................................................................................
123
Synchronize
语句
....................................................................................................................
123
Try
语句
..................................................................................................................................
124
Throw
语句
.............................................................................................................................
125
Volatile
语句
............................................................................................................................
125
Asm
语句
................................................................................................................................
126
数组
.................................................................................................................................................
128
指针
.........................................................................................................................................
128
静态数组
.................................................................................................................................
128
动态数组
.................................................................................................................................
128
数组声明
.................................................................................................................................
129
前缀数组声明
.................................................................................................................
129
后缀数组声明
.................................................................................................................
129
用法
.........................................................................................................................................
130
切片
.........................................................................................................................................
130
数组复制
.................................................................................................................................
131
数组赋值
.................................................................................................................................
132
数组连接
.................................................................................................................................
132
数组运算
.................................................................................................................................
133
示例:
.............................................................................................................................
133
矩形数组
.................................................................................................................................
134
数组长度
.................................................................................................................................
134
数组属性
.................................................................................................................................
135
设置动态数组的长度
.....................................................................................................
135
数组越界检查
.........................................................................................................................
137
数组初始化
.............................................................................................................................
138
静态数组的静态初始化
.................................................................................................
138
特殊数组型别
.........................................................................................................................
138
位数组
.............................................................................................................................
138
字符串
.............................................................................................................................
139
隐式转换
.........................................................................................................................
140
关联数组
(
哈希表
)
..................................................................................................................
141