Changeset 03c0e44 for doc/theses


Ignore:
Timestamp:
May 27, 2021, 3:28:57 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
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
Message:

Andrew MMath: Rewrote the existing features/references piece.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/existing.tex

    rab388c5 r03c0e44  
    4242
    4343\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.
     45They work very similarly to pointers.
     46Reference-types are written the same way as a pointer-type is but each
     47asterisk (@*@) is replaced with a ampersand (@&@);
     48this includes cv-qualifiers and multiple levels of reference.
     49
     50They are intended for cases where you would want to use pointers but would
     51be dereferencing them (almost) every usage.
     52In most cases a reference can just be thought of as a pointer that
     53automatically puts a dereference infront of each of its uses (per-level of
     54reference).
     55The address-of operator (@&@) acts as an escape and removes one of the
     56automatic dereference operations.
     57Mutable references may be assigned to by converting them to a pointer
     58with a @&@ and then assigning a pointer too them.
     59
     60\begin{minipage}{0,5\textwidth}
     61With references:
    5062\begin{cfa}
    5163int 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}
     64int & ri = i;
     65int && rri = ri;
     66rri = 3;
     67&ri = &j;
     68ri = 5;
     69\end{cfa}
     70\end{minipage}
     71\begin{minipage}{0,5\textwidth}
     72With pointers:
     73\begin{cfa}
     74int i, j;
     75int * pi = &i
     76int ** ppi = &pi;
     77**ppi = 3;
     78pi = &j;
     79*pi = 5;
     80\end{cfa}
     81\end{minipage}
    5782
    5883\section{Constructors and Destructors}
Note: See TracChangeset for help on using the changeset viewer.