Skip to content

Commit a2e345c

Browse files
committed
Improve pointer slicing example
1 parent 5582280 commit a2e345c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

spec/arrays.dd

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,14 @@ $(SPEC_RUNNABLE_EXAMPLE_RUN
306306
int[10] a = [ 1,2,3,4,5,6,7,8,9,10 ];
307307

308308
int* p = &a[2];
309-
int[] b = p[0..8];
310-
writeln(b);
311309
writeln(p[7]); // 10
312310
writeln(p[8]); // undefined behaviour
311+
312+
int[] b = p[0..8]; // convert pointer elements to dynamic array
313+
assert(b is a[2..10]);
314+
writeln(b);
313315
writeln(b[7]); // 10
314-
//writeln(b[8]); // range error
316+
//writeln(b[8]); // runtime error (unless bounds checks turned off)
315317
---------
316318
)
317319

0 commit comments

Comments
 (0)