@@ -180,6 +180,7 @@ $(H2 $(LNAME2 stringof, .stringof Property))
180
180
of that expression. The expression will not be evaluated.
181
181
)
182
182
183
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
183
184
---
184
185
module test;
185
186
import std.stdio;
@@ -193,17 +194,18 @@ $(H2 $(LNAME2 stringof, .stringof Property))
193
194
void main()
194
195
{
195
196
writeln((1+2).stringof); // "1 + 2"
197
+ writeln(test.stringof); // "module test"
196
198
writeln(Dog.stringof); // "Dog"
197
- writeln(test.Dog.stringof); // "Dog"
198
199
writeln(int.stringof); // "int"
199
200
writeln((int*[5][]).stringof); // "int*[5][]"
200
201
writeln(Color.Red.stringof); // "Red"
201
202
writeln((5).stringof); // "5"
202
203
203
204
writeln((++i).stringof); // "i += 1"
204
- writeln(i ); // 4
205
+ assert(i == 4 ); // `++i` was not evaluated
205
206
}
206
207
---
208
+ )
207
209
208
210
$(IMPLEMENTATION_DEFINED The string representation for a type or expression
209
211
can vary.)
@@ -223,32 +225,32 @@ $(H2 $(LNAME2 sizeof, .sizeof Property))
223
225
there to be a $(I this) object:
224
226
)
225
227
228
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
226
229
---
227
230
struct S
228
231
{
229
232
int a;
230
- static int foo()
231
- {
232
- return a.sizeof; // returns 4
233
- }
234
233
}
235
234
236
- void test()
237
- {
238
- int x = S.a.sizeof; // sets x to 4
239
- }
235
+ static assert(S.a.sizeof == 4);
236
+ static assert(Object.sizeof == (void*).sizeof);
240
237
---
238
+ )
241
239
242
240
$(P $(CODE .sizeof) applied to a class object returns the size of
243
241
the class reference, not the class instantiation.)
244
242
243
+ $(P See also: $(DDSUBLINK spec/traits, classInstanceSize, `__traits(classInstanceSize)`).)
244
+
245
245
$(H2 $(LNAME2 alignof, .alignof Property))
246
246
247
247
$(P $(CODE .alignof) gives the aligned size of an expression or type.
248
248
For example, an aligned size of 1 means that it is aligned on
249
249
a byte boundary, 4 means it is aligned on a 32 bit boundary.
250
250
)
251
251
252
+ $(P See $(DDSUBLINK spec/attribute, align, the `align` attribute) for an example.)
253
+
252
254
$(IMPLEMENTATION_DEFINED the actual aligned size.)
253
255
254
256
$(BEST_PRACTICE Be particularly careful when laying out an object that must
0 commit comments