@@ -96,15 +96,21 @@ $(GLINK OrOrExpression) (`||`), such that $(I expr) is a subexpression of $(I sc
96
96
---
97
97
((f() * 2 && g()) + 1) || h()
98
98
---
99
- The smallest short-circuit expression
100
- of the subexpression `f() * 2` above is `f() * 2 && g()`. Example:
99
+ $(P The smallest short-circuit expression
100
+ of the subexpression `f() * 2` above is `f() * 2 && g()`. Example:)
101
101
---
102
102
(f() && g()) + h()
103
103
---
104
- The subexpression `h()` above has no smallest short-circuit expression.
104
+ $(P The subexpression `h()` above has no smallest short-circuit expression.)
105
+
105
106
106
107
$(H2 $(LNAME2 order-of-evaluation, Order Of Evaluation))
107
108
109
+ $(BEST_PRACTICE Even when the order of evaluation is well-defined, writing code that
110
+ depends on it is rarely recommended.)
111
+
112
+ $(H3 $(LNAME2 order-increment, Increment and Decrement))
113
+
108
114
$(P Built-in prefix unary expressions `++` and `--` are evaluated as if lowered (rewritten) to
109
115
$(RELATIVE_LINK2 assignment_operator_expressions, assignments) as follows:)
110
116
@@ -129,6 +135,21 @@ $(TABLE
129
135
$(P Therefore, the result of postfix
130
136
`++` and `--` is an rvalue just before the side effect has been effected.)
131
137
138
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
139
+ ---
140
+ int i = 0;
141
+ assert(++i == 1);
142
+ assert(i++ == 1);
143
+ assert(i == 2);
144
+
145
+ int* p = [1, 2].ptr;
146
+ assert(*p++ == 1);
147
+ assert(*p == 2);
148
+ ---
149
+ )
150
+
151
+ $(H3 $(LNAME2 order-binary, Binary Expressions))
152
+
132
153
$(P Binary expressions except for $(GLINK AssignExpression), $(GLINK OrOrExpression), and
133
154
$(GLINK AndAndExpression) are evaluated in lexical order (left-to-right). Example:)
134
155
@@ -145,14 +166,24 @@ first. Then, $(GLINK OrOrExpression) evaluates its right-hand side if and only i
145
166
side does not evaluate to nonzero. $(GLINK AndAndExpression) evaluates its right-hand side if and
146
167
only if its left-hand side evaluates to nonzero.)
147
168
169
+ $(IMPLEMENTATION_DEFINED The order of evaluation of the operands of $(GLINK AssignExpression).)
170
+
171
+ $(H3 $(LNAME2 order-conditional, Conditional Expressions))
172
+
148
173
$(P $(GLINK ConditionalExpression) evaluates its left-hand side argument
149
174
first. Then, if the result is nonzero, the second operand is evaluated. Otherwise, the third operand
150
175
is evaluated.)
151
176
177
+ $(H3 $(LNAME2 order-calls, Function Calls))
178
+
152
179
$(P Calls to functions with `extern(D)` $(DDSUBLINK spec/attribute, linkage, linkage) (which is
153
- the default linkage) are evaluated in the following order: first, if necessary, the address of the
154
- function to call is evaluated (e.g. in the case of a computed function pointer or delegate). Then,
155
- arguments are evaluated left to right. Finally, transfer is passed to the function. Example:)
180
+ the default linkage) are evaluated in the following order:)
181
+ 1. If necessary, the address of the
182
+ function to call is evaluated (e.g. in the case of a computed function pointer or delegate).
183
+ 1. Arguments are evaluated left to right.
184
+ 1. Transfer of execution is passed to the function.
185
+
186
+ $(P Example calling a $(DDSUBLINK spec/function, function-pointers, function pointer):)
156
187
157
188
$(SPEC_RUNNABLE_EXAMPLE_RUN
158
189
---
@@ -173,14 +204,8 @@ fun()(f1(), f3(f2()), f4());
173
204
---
174
205
)
175
206
176
- $(IMPLEMENTATION_DEFINED
177
- $(OL
178
- $(LI The order of evaluation of the operands of $(GLINK AssignExpression).)
179
- $(LI The order of evaluation of function arguments for functions with linkage other than `extern (D)`.)
180
- ))
207
+ $(IMPLEMENTATION_DEFINED The order of evaluation of function arguments for functions with linkage other than `extern(D)`.)
181
208
182
- $(BEST_PRACTICE Even though the order of evaluation is well-defined, writing code that
183
- depends on it is rarely recommended.)
184
209
185
210
$(H2 $(LNAME2 temporary-lifetime, Lifetime of Temporaries))
186
211
0 commit comments