Changeset 21995bc for src/examples/wrapper
- Timestamp:
- May 18, 2016, 11:42:10 AM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 6e3ae00
- Parents:
- bf1ee05
- Location:
- src/examples/wrapper/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/wrapper/src/main.c
rbf1ee05 r21995bc 1 1 #include "pointer.h" 2 3 wrapper_t make_copy(wrapper_t copy) 4 { 5 return copy; 6 } 2 7 3 8 int main(int argc, char const *argv[]) 4 9 { 5 10 wrapper_t p = wrap(6); 11 12 sout | endl | "test started" | endl; 13 14 wrapper_t p2 = p; 15 16 clear(&p); 17 18 p = p2; 19 20 wrapper_t p3 = make_copy(p2); 21 22 sout | endl | "test ended" | endl; 23 6 24 return 0; 7 25 } -
src/examples/wrapper/src/pointer.h
rbf1ee05 r21995bc 53 53 void ?{}(wrapper_t* this) 54 54 { 55 sout | "Constructing empty ref pointer" | endl ;55 sout | "Constructing empty ref pointer" | endl | endl; 56 56 this->ptr = NULL; 57 57 } … … 62 62 this->ptr = rhs.ptr; 63 63 this->ptr->count++; 64 sout | "Reference is " | this->ptr->count | endl | endl; 64 65 } 65 66 … … 70 71 sout | "Destroying ref pointer" | endl; 71 72 this->ptr->count--; 72 sout | "Reference is " | (int)this->ptr->count| endl;73 sout | "Reference is " | this->ptr->count | endl | endl; 73 74 if(!this->ptr->count) delete(this->ptr); 74 75 } 75 76 else 76 77 { 77 sout | "Destroying empty ref pointer" | endl ;78 sout | "Destroying empty ref pointer" | endl | endl; 78 79 } 80 } 81 82 wrapper_t ?=?(wrapper_t* this, wrapper_t rhs) 83 { 84 sout | "Setting ref pointer" | endl; 85 if(this->ptr) 86 { 87 this->ptr->count--; 88 sout | "Reference is " | this->ptr->count | endl | endl; 89 if(!this->ptr->count) delete(this->ptr); 90 } 91 this->ptr = rhs.ptr; 92 this->ptr->count++; 93 sout | "Reference is " | this->ptr->count | endl | endl; 79 94 } 80 95 … … 84 99 this->ptr->count++; 85 100 sout | "Setting ref pointer" | endl; 86 sout | "Reference is " | this->ptr->count | endl ;101 sout | "Reference is " | this->ptr->count | endl | endl; 87 102 } 103 104 void clear(wrapper_t* this) 105 { 106 sout | "Clearing ref pointer" | endl; 107 this->ptr->count--; 108 sout | "Reference is " | this->ptr->count | endl | endl; 109 if(!this->ptr->count) delete(this->ptr); 110 this->ptr = NULL; 111 } 112 88 113 89 114 wrapper_t wrap(int val)
Note: See TracChangeset
for help on using the changeset viewer.