Rune - Further Object abstraction work
[rune.git] / tests / bounds.d
1 #!/usr/local/bin/rune -x
2 #
3 #       Demonstrate array bounds checking
4
5 import "sys";
6 import <stdio>;
7
8 alias stdio.File @stdout = stdio.stdout;
9
10 int
11 main(int ac, string_p *av)
12 {
13     string_p s = "charlie";
14     char buf[32];
15 #    char *ptr = s;     
16 #    char *ptr = &buf[0];       
17     char *ptr = &buf[1];        
18     char c;
19
20 #    for (int i = 0; i < 33; ++i) {
21 #       stdio.show("loop", i);
22 #       c = ptr[i];
23 #    }
24     int x = 1;
25
26     stdout->show("loop 32 should be out of bounds");
27     for (int i = 0; i < 33; ++i) {
28         stdout->show("loop", i);
29         c = *ptr;
30         ptr = ptr + 1;
31         ptr += x;
32         ptr -= 1;
33     }
34 }