ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 912cc7d7 was
aabb846,
checked in by Andrew Beach <ajbeach@…>, 4 years ago
|
Added a first draft of the memory management library module.
|
-
Property mode set to
100644
|
File size:
976 bytes
|
Line | |
---|
1 | // Testing the smart pointers (counter_ptr and unique_ptr). |
---|
2 | |
---|
3 | #include <memory.hfa> |
---|
4 | #include <stdlib.hfa> |
---|
5 | |
---|
6 | void counter_test(void) { |
---|
7 | counter_ptr(int) ptr0 = 3; |
---|
8 | |
---|
9 | { |
---|
10 | counter_ptr(int) ptr1 = ptr0; |
---|
11 | *ptr1 = -7; |
---|
12 | } |
---|
13 | assert(-7 == *ptr0); |
---|
14 | |
---|
15 | { |
---|
16 | counter_ptr(int) ptr2 = 4; |
---|
17 | ptr0 = ptr2; |
---|
18 | } |
---|
19 | assert(4 == *ptr0); |
---|
20 | |
---|
21 | { |
---|
22 | counter_ptr(int) ptr3 = ptr0; |
---|
23 | counter_ptr(int) ptr4 = ptr0; |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | void unique_test(void) { |
---|
28 | unique_ptr(char) ptr_a = 'a'; |
---|
29 | unique_ptr(char) ptr_b = 'b'; |
---|
30 | move(ptr_a, ptr_b); |
---|
31 | assert(ptr_b == 0); |
---|
32 | assert(*ptr_a == 'b'); |
---|
33 | |
---|
34 | unique_ptr(char) ptr_c = 'c'; |
---|
35 | ptr_c = 0; |
---|
36 | } |
---|
37 | |
---|
38 | void pointer_equality(void) { |
---|
39 | { |
---|
40 | counter_ptr(int) null = 0p; |
---|
41 | assert(null == 0); |
---|
42 | counter_ptr(int) hold = -7; |
---|
43 | assert(hold != 0); |
---|
44 | counter_ptr(int) twin = hold; |
---|
45 | assert(hold == twin); |
---|
46 | } |
---|
47 | { |
---|
48 | unique_ptr(int) null = 0p; |
---|
49 | assert(null == 0); |
---|
50 | unique_ptr(int) hold = -7; |
---|
51 | assert(hold != 0); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | int main(int argc, char * argv[]) { |
---|
56 | counter_test(); |
---|
57 | unique_test(); |
---|
58 | pointer_equality(); |
---|
59 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.