Mercurial > projects > ldc
comparison test/ptrarith.d @ 1:c53b6e3fe49a trunk
[svn r5] Initial commit. Most things are very rough.
author | lindquist |
---|---|
date | Sat, 01 Sep 2007 21:43:27 +0200 |
parents | |
children | d9d5d59873d8 |
comparison
equal
deleted
inserted
replaced
0:a9e71648e74d | 1:c53b6e3fe49a |
---|---|
1 void main() | |
2 { | |
3 printf("Pointer arithmetic test\n"); | |
4 int* p; | |
5 printf("0x%x\n", p); | |
6 assert(p++ is null); | |
7 assert(cast(size_t)p == 4); | |
8 printf("0x%x\n", p); | |
9 p--; | |
10 assert(p is null); | |
11 printf("0x%x\n", p); | |
12 int d = 4; | |
13 p+=d; | |
14 printf("0x%x\n", p); | |
15 assert(cast(size_t)p == 16); | |
16 d = 2; | |
17 p+=d; | |
18 printf("0x%x\n", p); | |
19 assert(cast(size_t)p == 0x18); | |
20 d = 6; | |
21 p-=d; | |
22 printf("0x%x\n", p); | |
23 assert(p is null); | |
24 printf(" SUCCESS\n"); | |
25 } | |
26 | |
27 void fill_byte_array(ubyte* a, size_t n, ubyte v) | |
28 { | |
29 auto p = a; | |
30 auto end = a+n; | |
31 while (p !is end) | |
32 *p++ = v; | |
33 } |