comparison tests/mini/foreach10.d @ 1185:8baf611f0009

Fix nested references to 'ref' foreach variables. These "walk around" the array being iterated over, so they're a bit trickier than other variables to get right.
author Frits van Bommel <fvbommel wxs.nl>
date Wed, 01 Apr 2009 00:01:44 +0200
parents
children
comparison
equal deleted inserted replaced
1183:df386fd4030e 1185:8baf611f0009
1 module foreach10;
2
3 extern(C) int printf(char*, ...);
4
5 void main() {
6 char* last = null;
7 printf("The addresses should increment:\n");
8 foreach (ref c; "bar") {
9 auto a = {
10 printf("%x '%c'\n", c, c);
11 return &c;
12 };
13 auto nw = a();
14 printf("ptr = %p\n", nw);
15 if (last != null)
16 assert(nw == last+1);
17 last = nw;
18 }
19 }