Changeset 03c0e44
- Timestamp:
- May 27, 2021, 3:28:57 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- e72969a
- Parents:
- ab388c5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/existing.tex
rab388c5 r03c0e44 42 42 43 43 \section{Reference Type} 44 \CFA adds a rebindable reference type to C, but more expressive than the \Cpp 45 reference. Multi-level references are allowed and act like auto-dereferenced 46 pointers using the ampersand (@&@) instead of the pointer asterisk (@*@). \CFA 47 references may also be mutable or non-mutable. If mutable, a reference variable 48 may be assigned using the address-of operator (@&@), which converts the 49 reference to a pointer. 44 \CFA adds a reference type to C as an auto-dereferencing pointer. 45 They work very similarly to pointers. 46 Reference-types are written the same way as a pointer-type is but each 47 asterisk (@*@) is replaced with a ampersand (@&@); 48 this includes cv-qualifiers and multiple levels of reference. 49 50 They are intended for cases where you would want to use pointers but would 51 be dereferencing them (almost) every usage. 52 In most cases a reference can just be thought of as a pointer that 53 automatically puts a dereference infront of each of its uses (per-level of 54 reference). 55 The address-of operator (@&@) acts as an escape and removes one of the 56 automatic dereference operations. 57 Mutable references may be assigned to by converting them to a pointer 58 with a @&@ and then assigning a pointer too them. 59 60 \begin{minipage}{0,5\textwidth} 61 With references: 50 62 \begin{cfa} 51 63 int i, j; 52 int & ri = i, && rri = ri; 53 rri = 3; // auto-dereference assign to i 54 &ri = &j; // rebindable 55 ri = 5; // assign to j 56 \end{cfa} 64 int & ri = i; 65 int && rri = ri; 66 rri = 3; 67 &ri = &j; 68 ri = 5; 69 \end{cfa} 70 \end{minipage} 71 \begin{minipage}{0,5\textwidth} 72 With pointers: 73 \begin{cfa} 74 int i, j; 75 int * pi = &i 76 int ** ppi = π 77 **ppi = 3; 78 pi = &j; 79 *pi = 5; 80 \end{cfa} 81 \end{minipage} 57 82 58 83 \section{Constructors and Destructors}
Note: See TracChangeset
for help on using the changeset viewer.