comparison tests/mini/ptrarith.d @ 341:1bb99290e03a trunk

[svn r362] Started merging the old 'test' dir as well as the newer 'tangotests' dir into 'tests/mini' and 'tests/minicomplex'.
author lindquist
date Sun, 13 Jul 2008 02:51:19 +0200
parents test/ptrarith.d@d9d5d59873d8
children
comparison
equal deleted inserted replaced
340:351c0077d0b3 341:1bb99290e03a
1 extern(C) int printf(char*, ...);
2
3 void main()
4 {
5 printf("Pointer arithmetic test\n");
6 int* p;
7 printf("0x%x\n", p);
8 assert(p++ is null);
9 assert(cast(size_t)p == 4);
10 printf("0x%x\n", p);
11 p--;
12 assert(p is null);
13 printf("0x%x\n", p);
14 int d = 4;
15 p+=d;
16 printf("0x%x\n", p);
17 assert(cast(size_t)p == 16);
18 d = 2;
19 p+=d;
20 printf("0x%x\n", p);
21 assert(cast(size_t)p == 0x18);
22 d = 6;
23 p-=d;
24 printf("0x%x\n", p);
25 assert(p is null);
26 printf(" SUCCESS\n");
27 }
28
29 void fill_byte_array(ubyte* a, size_t n, ubyte v)
30 {
31 auto p = a;
32 auto end = a+n;
33 while (p !is end)
34 *p++ = v;
35 }