Changeset f4eb705


Ignore:
Timestamp:
Feb 9, 2021, 4:51:22 PM (7 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
52f6250
Parents:
d4a4b17 (diff), 735b627 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.tex

    rd4a4b17 rf4eb705  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Wed Feb  3 10:57:33 2021
    14 %% Update Count     : 508
     13%% Last Modified On : Mon Feb  8 21:45:41 2021
     14%% Update Count     : 522
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    5757  \pdfstringdefDisableCommands{
    5858  \def\CFA{\CFL}
     59  \def\Celeven{C11\xspace}
    5960  \def\CC{C++\xspace}
    6061  \def\CCeleven{C++11\xspace}
     
    6364  \def\CCtwenty{C++20\xspace}
    6465  \def\Csharp{C\#\xspace}
    65   \def\lstinline{\xspace} % must use {} as delimiters, e.g., \lstinline{...}
     66  \def\lstinline{\xspace}% must use {} as delimiters, e.g., \lstinline{...}
    6667  }{}
    6768}
     
    9798    \vskip 50\p@
    9899  }}
    99 \renewcommand\section{\@startsection{section}{1}{\z@}{-3.5ex \@plus -1ex \@minus -.2ex}{1.75ex \@plus .2ex}{\normalfont\large\bfseries}}
    100 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-3.25ex \@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
     100\renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}{\normalfont\large\bfseries}}
     101\renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.75ex \@plus -1ex \@minus -.2ex}{1.25ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    101102\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    102103\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}}
     
    251252\newcommand{\LstKeywordStyle}[1]{{\lst@basicstyle{\lst@keywordstyle{#1}}}}
    252253\newcommand{\LstCommentStyle}[1]{{\lst@basicstyle{\lst@commentstyle{#1}}}}
     254\newcommand{\LstStringStyle}[1]{{\lst@basicstyle{\lst@stringstyle{#1}}}}
    253255
    254256\newlength{\gcolumnposn}                                % temporary hack because lstlisting does not handle tabs correctly
     
    276278xleftmargin=\parindentlnth,                             % indent code to paragraph indentation
    277279extendedchars=true,                                             % allow ASCII characters in the range 128-255
    278 escapechar=§,                                                   % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
    279 mathescape=true,                                                % LaTeX math escape in CFA code $...$
     280escapechar=\$,                                                  % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
     281mathescape=false,                                               % LaTeX math escape in CFA code $...$
    280282keepspaces=true,                                                %
    281283showstringspaces=false,                                 % do not show spaces with cup
     
    295297\lstset{
    296298language=CFA,
    297 moredelim=**[is][\color{red}]{®}{®},    % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
    298 moredelim=**[is][\color{blue}]{ß}{ß},   % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
    299 moredelim=**[is][\color{OliveGreen}]{¢}{¢}, % green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
    300 moredelim=[is][\lstset{keywords={}}]{¶}{¶}, % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
    301 % replace/adjust listing characters that look bad in sanserif
    302 add to literate={`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
     299moredelim=**[is][\color{red}]{@}{@},    % red highlighting @...@
     300%moredelim=**[is][\color{red}]{®}{®},   % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
     301%moredelim=**[is][\color{blue}]{ß}{ß},  % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
     302%moredelim=**[is][\color{OliveGreen}]{¢}{¢}, % green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
     303%moredelim=[is][\lstset{keywords={}}]{¶}{¶}, % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
    303304}% lstset
    304305\lstset{#1}
  • doc/theses/fangren_yu_COOP_F20/Report.tex

    rd4a4b17 rf4eb705  
    102102\CFA language, developed by the Programming Language Group at the University of Waterloo, has a long history, with the initial language design in 1992 by Glen Ditchfield~\cite{Ditchfield92} and the first proof-of-concept compiler built in 2003 by Richard Bilson~\cite{Bilson03}. Many new features have been added to the language over time, but the core of \CFA's type-system --- parametric functions introduced by the @forall@ clause (hence the name of the language) providing parametric overloading --- remains mostly unchanged.
    103103
    104 The current \CFA reference compiler, @cfa-cc@, is designed using the visitor pattern~\cite{vistorpattern} over an abstract syntax tree (AST), where multiple passes over the AST modify it for subsequent passes. @cfa-cc@ still includes many parts taken directly from the original Bilson implementation, which served as the starting point for this enhancement work to the type system. Unfortunately, the prior implementation did not provide the efficiency required for the language to be practical: a \CFA source file of approximately 1000 lines of code can take a multiple minutes to compile. The cause of the problem is that the old compiler used inefficient data structures and algorithms for expression resolution, which involved significant copying and redundant work.
     104The current \CFA reference compiler, @cfa-cc@, is designed using the visitor pattern~\cite{vistorpattern} over an abstract syntax tree (AST), where multiple passes over the AST modify it for subsequent passes. @cfa-cc@ still includes many parts taken directly from the original Bilson implementation, which served as the starting point for this enhancement work to the type system. Unfortunately, the prior implementation did not provide the efficiency required for the language to be practical: a \CFA source file of approximately 1000 lines of code can take multiple minutes to compile. The cause of the problem is that the old compiler used inefficient data structures and algorithms for expression resolution, which involved significant copying and redundant work.
    105105
    106106This report presents a series of optimizations to the performance-critical parts of the resolver, with a major rework of the compiler data-structures using a functional-programming approach to reduce memory complexity. The improvements were suggested by running the compiler builds with a performance profiler against the \CFA standard-library source-code and a test suite to find the most underperforming components in the compiler algorithm.
     
    122122\end{itemize}
    123123
    124 The resolver algorithm, designed for overload resolution, uses a significant amount of reused, and hence copying, for the intermediate representations, especially in the following two places:
     124The resolver algorithm, designed for overload resolution, allows a significant amount of code reused, and hence copying, for the intermediate representations, especially in the following two places:
    125125\begin{itemize}
    126126\item
     
    301301forall( dtype T | sized( T ) )
    302302T * malloc( void ) { return (T *)malloc( sizeof(T) ); } // call C malloc
    303 int * i = malloc();  // type deduced from left-hand size $\Rightarrow$ no size argument or return cast
     303int * i = malloc();  // type deduced from left-hand size $\(\Rightarrow\)$ no size argument or return cast
    304304\end{cfa}
    305305An unbound return-type is problematic in resolver complexity because a single match of a function call with an unbound return type may create multiple candidates. In the worst case, consider a function declared that returns any @otype@ (defined \VPageref{otype}):
     
    432432\begin{cfa}
    433433void f( int );
    434 double g$_1$( int );
    435 int g$_2$( long );
     434double g$\(_1\)$( int );
     435int g$\(_2\)$( long );
    436436f( g( 42 ) );
    437437\end{cfa}
  • doc/user/figures/Cdecl.fig

    rd4a4b17 rf4eb705  
    19192 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
    2020         2850 1200 3600 1200 3600 1350 2850 1350 2850 1200
    21 4 1 0 50 -1 4 10 0.0000 2 120 90 2925 1325 0\001
    22 4 1 0 50 -1 4 10 0.0000 2 120 90 3075 1325 1\001
    23 4 1 0 50 -1 4 10 0.0000 2 120 90 3225 1325 2\001
    24 4 1 0 50 -1 4 10 0.0000 2 120 90 3375 1325 3\001
    25 4 1 0 50 -1 4 10 0.0000 2 120 90 3525 1325 4\001
     214 1 0 50 -1 4 11 0.0000 2 120 90 2925 1325 0\001
     224 1 0 50 -1 4 11 0.0000 2 120 90 3075 1325 1\001
     234 1 0 50 -1 4 11 0.0000 2 120 90 3225 1325 2\001
     244 1 0 50 -1 4 11 0.0000 2 120 90 3375 1325 3\001
     254 1 0 50 -1 4 11 0.0000 2 120 90 3525 1325 4\001
    2626-6
    27272 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
     
    5555        1 1 1.00 45.00 60.00
    5656         2550 1275 2850 1275
    57 4 1 0 50 -1 4 10 0.0000 2 120 90 1350 1650 0\001
    58 4 1 0 50 -1 4 10 0.0000 2 120 90 1500 1650 1\001
    59 4 1 0 50 -1 4 10 0.0000 2 120 90 1650 1650 2\001
    60 4 1 0 50 -1 4 10 0.0000 2 120 90 1800 1650 3\001
    61 4 1 0 50 -1 4 10 0.0000 2 120 90 1950 1650 4\001
    62 4 1 0 50 -1 4 10 0.0000 2 90 90 1200 1325 x\001
    63 4 1 0 50 -1 4 10 0.0000 2 90 90 2400 1325 x\001
     574 1 0 50 -1 4 11 0.0000 2 120 90 1350 1650 0\001
     584 1 0 50 -1 4 11 0.0000 2 120 90 1500 1650 1\001
     594 1 0 50 -1 4 11 0.0000 2 120 90 1650 1650 2\001
     604 1 0 50 -1 4 11 0.0000 2 120 90 1800 1650 3\001
     614 1 0 50 -1 4 11 0.0000 2 120 90 1950 1650 4\001
     624 1 0 50 -1 4 11 0.0000 2 90 90 1200 1325 x\001
     634 1 0 50 -1 4 11 0.0000 2 90 90 2400 1325 x\001
  • doc/user/user.tex

    rd4a4b17 rf4eb705  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Oct  5 08:57:29 2020
    14 %% Update Count     : 3998
     13%% Last Modified On : Mon Feb  8 21:53:31 2021
     14%% Update Count     : 4327
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    3737\usepackage{mathptmx}                                   % better math font with "times"
    3838\usepackage[usenames]{color}
     39\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
     40\usepackage{breakurl}
     41
     42\renewcommand\footnoterule{\kern -3pt\rule{0.3\linewidth}{0.15pt}\kern 2pt}
     43
     44\usepackage[pagewise]{lineno}
     45\renewcommand{\linenumberfont}{\scriptsize\sffamily}
     46\usepackage[firstpage]{draftwatermark}
     47\SetWatermarkLightness{0.9}
     48
     49% Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
     50% removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
     51% AFTER HYPERREF.
     52\renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
     53
     54\setlength{\topmargin}{-0.45in}                                                 % move running title into header
     55\setlength{\headsep}{0.25in}
     56
     57%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     58
    3959\newcommand{\CFALatin}{}
    4060% inline code ©...© (copyright symbol) emacs: C-q M-)
     
    4666% math escape $...$ (dollar symbol)
    4767\input{common}                                          % common CFA document macros
    48 \usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
    49 \usepackage{breakurl}
    50 
    51 \renewcommand\footnoterule{\kern -3pt\rule{0.3\linewidth}{0.15pt}\kern 2pt}
    52 
    53 \usepackage[pagewise]{lineno}
    54 \renewcommand{\linenumberfont}{\scriptsize\sffamily}
    55 \usepackage[firstpage]{draftwatermark}
    56 \SetWatermarkLightness{0.9}
    57 
    58 % Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
    59 % removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
    60 % AFTER HYPERREF.
    61 \renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
    62 
    63 \setlength{\topmargin}{-0.45in}                                                 % move running title into header
    64 \setlength{\headsep}{0.25in}
    65 
    66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    67 
    6868\CFAStyle                                                                                               % use default CFA format-style
     69\lstset{language=CFA}                                                                   % CFA default lnaguage
    6970\lstnewenvironment{C++}[1][]                            % use C++ style
    70 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®},#1}}
     71{\lstset{language=C++,moredelim=**[is][\protect\color{red}]{@}{@},#1}}
    7172{}
    7273
     
    8182\newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
    8283\newcommand{\R}[1]{\Textbf{#1}}
     84\newcommand{\RC}[1]{\Textbf{\LstBasicStyle{#1}}}
    8385\newcommand{\B}[1]{{\Textbf[blue]{#1}}}
    8486\newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}}
     
    104106\author{
    105107\huge \CFA Team \medskip \\
    106 \Large Andrew Beach, Richard Bilson, Peter A. Buhr, Thierry Delisle, \smallskip \\
    107 \Large Glen Ditchfield, Rodolfo G. Esteves, Aaron Moss, Rob Schluntz
     108\Large Andrew Beach, Richard Bilson, Michael Brooks, Peter A. Buhr, Thierry Delisle, \smallskip \\
     109\Large Glen Ditchfield, Rodolfo G. Esteves, Aaron Moss, Colby Parsons, Rob Schluntz, \smallskip \\
     110\Large Fangren Yu, Mubeen Zulfiqar
    108111}% author
    109112
     
    144147\section{Introduction}
    145148
    146 \CFA{}\index{cforall@\CFA}\footnote{Pronounced ``\Index*{C-for-all}'', and written \CFA, CFA, or \CFL.} is a modern general-purpose programming-language, designed as an evolutionary step forward for the C programming language.
     149\CFA{}\index{cforall@\CFA}\footnote{Pronounced ``\Index*{C-for-all}'', and written \CFA, CFA, or \CFL.} is a modern general-purpose concurrent programming-language, designed as an evolutionary step forward for the C programming language.
    147150The syntax of \CFA builds from C and should look immediately familiar to C/\Index*[C++]{\CC{}} programmers.
    148151% Any language feature that is not described here can be assumed to be using the standard \Celeven syntax.
    149 \CFA adds many modern programming-language features that directly lead to increased \emph{\Index{safety}} and \emph{\Index{productivity}}, while maintaining interoperability with existing C programs and achieving similar performance.
     152\CFA adds many modern features that directly lead to increased \emph{\Index{safety}} and \emph{\Index{productivity}}, while maintaining interoperability with existing C programs and achieving similar performance.
    150153Like C, \CFA is a statically typed, procedural (non-\Index{object-oriented}) language with a low-overhead runtime, meaning there is no global \Index{garbage-collection}, but \Index{regional garbage-collection}\index{garbage-collection!regional} is possible.
    151154The primary new features include polymorphic routines and types, exceptions, concurrency, and modules.
     
    157160instead, a programmer evolves a legacy program into \CFA by incrementally incorporating \CFA features.
    158161As well, new programs can be written in \CFA using a combination of C and \CFA features.
     162In many ways, \CFA is to C as \Index{Scala}~\cite{Scala} is to Java, providing a vehicle for new typing and control-flow capabilities on top of a highly popular programming language allowing immediate dissemination.
    159163
    160164\Index*[C++]{\CC{}}~\cite{c++:v1} had a similar goal 30 years ago, allowing object-oriented programming to be incrementally added to C.
     
    165169For example, the following programs compare the C, \CFA, and \CC I/O mechanisms, where the programs output the same result.
    166170\begin{center}
    167 \begin{tabular}{@{}l@{\hspace{1.5em}}l@{\hspace{1.5em}}l@{}}
    168 \multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{C}} & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{\CC}}      \\
    169 \begin{cfa}
    170 #include <stdio.h>§\indexc{stdio.h}§
     171\begin{tabular}{@{}l@{\hspace{1em}}l@{\hspace{1em}}l@{}}
     172\multicolumn{1}{c@{\hspace{1em}}}{\textbf{C}}   & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{\CC}}      \\
     173\begin{cfa}
     174#include <stdio.h>$\indexc{stdio.h}$
    171175
    172176int main( void ) {
    173177        int x = 0, y = 1, z = 2;
    174         ®printf( "%d %d %d\n", x, y, z );®
     178        @printf( "%d %d %d\n", x, y, z );@
    175179}
    176180\end{cfa}
    177181&
    178182\begin{cfa}
    179 #include <fstream>§\indexc{fstream}§
     183#include <fstream>$\indexc{fstream}$
    180184
    181185int main( void ) {
    182186        int x = 0, y = 1, z = 2;
    183         ®sout | x | y | z;®§\indexc{sout}§
     187        @sout | x | y | z;@$\indexc{sout}$
    184188}
    185189\end{cfa}
    186190&
    187191\begin{cfa}
    188 #include <iostream>§\indexc{iostream}§
     192#include <iostream>$\indexc{iostream}$
    189193using namespace std;
    190194int main() {
    191195        int x = 0, y = 1, z = 2;
    192         ®cout<<x<<" "<<y<<" "<<z<<endl;®
     196        @cout<<x<<" "<<y<<" "<<z<<endl;@
    193197}
    194198\end{cfa}
    195199\end{tabular}
    196200\end{center}
    197 While the \CFA I/O looks similar to the \Index*[C++]{\CC{}} output style, there are important differences, such as automatic spacing between variables as in \Index*{Python} (see~\VRef{s:IOLibrary}).
     201While \CFA I/O \see{\VRef{s:StreamIOLibrary}} looks similar to \Index*[C++]{\CC{}}, there are important differences, such as automatic spacing between variables and an implicit newline at the end of the expression list, similar to \Index*{Python}~\cite{Python}.
    198202
    199203
     
    210214\section{Why fix C?}
    211215
    212 The C programming language is a foundational technology for modern computing with millions of lines of code implementing everything from hobby projects to commercial operating-systems.
     216The C programming language is a foundational technology for modern computing with billions of lines of code implementing everything from hobby projects to commercial operating-systems.
    213217This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
    214218Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    215 For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice.
    216 The TIOBE index~\cite{TIOBE} for February 2020 ranks the top six most \emph{popular} programming languages as \Index*{Java} 17.4\%, C 16.8\%, Python 9.3\%, \Index*[C++]{\CC{}} 6.2\%, \Csharp 5.9\%, Visual Basic 5.9\% = 61.5\%, where the next 50 languages are less than 2\% each, with a long tail.
     219For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is the only language of choice.
     220The TIOBE index~\cite{TIOBE} for February 2021 ranks the top six most \emph{popular} programming languages as C 17.4\%, \Index*{Java} 12\%, Python 12\%, \Index*[C++]{\CC{}} 7.6\%, \Csharp 4\%, Visual Basic 3.8\% = 56.8\%, where the next 50 languages are less than 2\% each, with a long tail.
    217221The top 4 rankings over the past 35 years are:
    218222\begin{center}
    219223\setlength{\tabcolsep}{10pt}
    220224\begin{tabular}{@{}rcccccccc@{}}
    221                 & 2020  & 2015  & 2010  & 2005  & 2000  & 1995  & 1990  & 1985  \\ \hline
    222 Java    & 1             & 2             & 1             & 2             & 3             & -             & -             & -             \\
    223 \R{C}   & \R{2} & \R{1} & \R{2} & \R{1} & \R{1} & \R{2} & \R{1} & \R{1} \\
    224 Python  & 3             & 7             & 6             & 6             & 22    & 21    & -             & -             \\
    225 \CC             & 4             & 4             & 4             & 3             & 2             & 1             & 2             & 12    \\
     225                & 2021  & 2016  & 2011  & 2006  & 2001  & 1996  & 1991  & 1986  \\ \hline
     226\R{C}   & \R{1} & \R{2} & \R{2} & \R{1} & \R{1} & \R{1} & \R{1} & \R{1} \\
     227Java    & 2             & 1             & 1             & 2             & 3             & 28    & -             & -             \\
     228Python  & 3             & 5             & 6             & 7             & 23    & 13    & -             & -             \\
     229\CC             & 4             & 3             & 3             & 3             & 2             & 2             & 2             & 8             \\
    226230\end{tabular}
    227231\end{center}
     
    232236As stated, the goal of the \CFA project is to engineer modern language-features into C in an evolutionary rather than revolutionary way.
    233237\CC~\cite{C++14,C++} is an example of a similar project;
    234 however, it largely extended the C language, and did not address most of C's existing problems.\footnote{%
     238however, it largely extended the C language, and did not address many of C's existing problems.\footnote{%
    235239Two important existing problems addressed were changing the type of character literals from ©int© to ©char© and enumerator from ©int© to the type of its enumerators.}
    236240\Index*{Fortran}~\cite{Fortran08}, \Index*{Ada}~\cite{Ada12}, and \Index*{Cobol}~\cite{Cobol14} are examples of programming languages that took an evolutionary approach, where modern language-features (\eg objects, concurrency) are added and problems fixed within the framework of the existing language.
     
    241245
    242246The result of this project is a language that is largely backwards compatible with \Index*[C11]{\Celeven{}}~\cite{C11}, but fixes many of the well known C problems while adding modern language-features.
    243 To achieve these goals required a significant engineering exercise, where we had to ``think inside the existing C box''.
    244 Without these significant extension to C, it is unable to cope with the needs of modern programming problems and programmers;
    245 as a result, it will fade into disuse.
    246 Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern programming language.
     247To achieve these goals required a significant engineering exercise, \ie ``thinking \emph{inside} the C box''.
     248Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern language.
    247249While \Index*[C11]{\Celeven{}} made a few simple extensions to the language, nothing was added to address existing problems in the language or to augment the language with modern language-features.
    248250While some may argue that modern language-features may make C complex and inefficient, it is clear a language without modern capabilities is insufficient for the advanced programming problems existing today.
     
    251253\section{History}
    252254
    253 The \CFA project started with \Index*{Dave Till}\index{Till, Dave}'s \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and advanced assignment capabilities using the notion of tuples.
    254 (See~\cite{Werther96} for similar work in \Index*[C++]{\CC{}}.)
     255The \CFA project started with \Index*{Dave Till}\index{Till, Dave}'s \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and advanced assignment capabilities using the notion of tuples \see{\cite{Werther96} for similar work in \Index*[C++]{\CC{}}}.
    255256The first \CFA implementation of these extensions was by \Index*{Rodolfo Esteves}\index{Esteves, Rodolfo}~\cite{Esteves04}.
    256257
    257258The signature feature of \CFA is \emph{\Index{overload}able} \Index{parametric-polymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name):
    258259\begin{cfa}
    259 ®forall( otype T )® T identity( T val ) { return val; }
    260 int forty_two = identity( 42 ); §\C{// T is bound to int, forty\_two == 42}§
     260@forall( otype T )@ T identity( T val ) { return val; }
     261int forty_two = identity( 42 ); $\C{// T is bound to int, forty\_two == 42}$
    261262\end{cfa}
    262263% extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions.
    263264\CFA{}\hspace{1pt}'s polymorphism was originally formalized by \Index*{Glen Ditchfield}\index{Ditchfield, Glen}~\cite{Ditchfield92}, and first implemented by \Index*{Richard Bilson}\index{Bilson, Richard}~\cite{Bilson03}.
    264265However, at that time, there was little interesting in extending C, so work did not continue.
    265 As the saying goes, ``\Index*{What goes around, comes around.}'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted.
     266As the saying goes, ``\Index*{What goes around, comes around.}'', and there is now renewed interest in the C programming language because of the legacy code-base, so the \CFA project was restarted in 2015.
    266267
    267268
     
    273274This feature allows \CFA programmers to take advantage of the existing panoply of C libraries to access thousands of external software features.
    274275Language developers often state that adequate \Index{library support} takes more work than designing and implementing the language itself.
    275 Fortunately, \CFA, like \Index*[C++]{\CC{}}, starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at very low cost.
     276Fortunately, \CFA, like \Index*[C++]{\CC{}}, starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at zero or very low cost.
    276277Hence, \CFA begins by leveraging the large repository of C libraries, and than allows programmers to incrementally augment their C programs with modern \Index{backward-compatible} features.
    277278
     
    286287
    287288double key = 5.0, vals[10] = { /* 10 sorted floating values */ };
    288 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); §\C{// search sorted array}§
     289double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$
    289290\end{cfa}
    290291which can be augmented simply with a polymorphic, type-safe, \CFA-overloaded wrappers:
     
    295296
    296297forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {
    297         T * result = bsearch( key, arr, size ); §\C{// call first version}§
    298         return result ? result - arr : size; } §\C{// pointer subtraction includes sizeof(T)}§
    299 
    300 double * val = bsearch( 5.0, vals, 10 ); §\C{// selection based on return type}§
     298        T * result = bsearch( key, arr, size ); $\C{// call first version}$
     299        return result ? result - arr : size; } $\C{// pointer subtraction includes sizeof(T)}$
     300
     301double * val = bsearch( 5.0, vals, 10 ); $\C{// selection based on return type}$
    301302int posn = bsearch( 5.0, vals, 10 );
    302303\end{cfa}
     
    310311\begin{cfa}
    311312forall( dtype T | sized(T) ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); }
    312 int * ip = malloc(); §\C{// select type and size from left-hand side}§
     313int * ip = malloc(); $\C{// select type and size from left-hand side}$
    313314double * dp = malloc();
    314315struct S {...} * sp = malloc();
     
    319320However, it is necessary to differentiate between C and \CFA code because of name \Index{overload}ing, as for \CC.
    320321For example, the C math-library provides the following routines for computing the absolute value of the basic types: ©abs©, ©labs©, ©llabs©, ©fabs©, ©fabsf©, ©fabsl©, ©cabsf©, ©cabs©, and ©cabsl©.
    321 Whereas, \CFA wraps each of these routines into ones with the overloaded name ©abs©:
    322 \begin{cfa}
    323 char ®abs®( char );
    324 extern "C" { int ®abs®( int ); } §\C{// use default C routine for int}§
    325 long int ®abs®( long int );
    326 long long int ®abs®( long long int );
    327 float ®abs®( float );
    328 double ®abs®( double );
    329 long double ®abs®( long double );
    330 float _Complex ®abs®( float _Complex );
    331 double _Complex ®abs®( double _Complex );
    332 long double _Complex ®abs®( long double _Complex );
    333 \end{cfa}
    334 The problem is the name clash between the library routine ©abs© and the \CFA names ©abs©.
    335 Hence, names appearing in an ©extern "C"© block have \newterm*{C linkage}.
    336 Then overloading polymorphism uses a mechanism called \newterm{name mangling}\index{mangling!name} to create unique names that are different from C names, which are not mangled.
    337 Hence, there is the same need, as in \CC, to know if a name is a C or \CFA name, so it can be correctly formed.
    338 There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and types.
    339 
    340 This example strongly illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
     322Whereas, \CFA wraps each of these routines into one overloaded name ©abs©:
     323\begin{cfa}
     324char @abs@( char );
     325extern "C" { int @abs@( int ); } $\C{// use default C routine for int}$
     326long int @abs@( long int );
     327long long int @abs@( long long int );
     328float @abs@( float );
     329double @abs@( double );
     330long double @abs@( long double );
     331float _Complex @abs@( float _Complex );
     332double _Complex @abs@( double _Complex );
     333long double _Complex @abs@( long double _Complex );
     334\end{cfa}
     335The problem is \Index{name clash} between the C name ©abs© and the \CFA names ©abs©, resulting in two name linkages\index{C linkage}: ©extern "C"© and ©extern "Cforall"© (default).
     336Overloaded names must use \newterm{name mangling}\index{mangling!name} to create unique names that are different from unmangled C names.
     337Hence, there is the same need as in \CC to know if a name is a C or \CFA name, so it can be correctly formed.
     338The only way around this problem is C's approach of creating unique names for each pairing of operation and type.
     339
     340This example illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
    341341The name ``©abs©'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value.
    342342Hence, knowing the name ©abs© is sufficient to apply it to any type where it is applicable.
     
    344344
    345345
    346 \section[Compiling a CFA Program]{Compiling a \CFA Program}
     346\section{\CFA Compilation}
    347347
    348348The command ©cfa© is used to compile a \CFA program and is based on the \Index{GNU} \Indexc{gcc} command, \eg:
    349349\begin{cfa}
    350 cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] [ C/§\CFA{}§ source-files ] [ assembler/loader files ]
    351 \end{cfa}
    352 \CFA programs having the following ©gcc© flags turned on:
    353 \begin{description}
     350cfa$\indexc{cfa}\index{compilation!cfa@©cfa©}$ [ gcc/$\CFA{}$-options ] [ C/$\CFA{}$ source-files ] [ assembler/loader files ]
     351\end{cfa}
     352There is no ordering among options (flags) and files, unless an option has an argument, which must appear immediately after the option possibly with or without a space separating option and argument.
     353
     354\CFA has the following ©gcc© flags turned on:
     355\begin{description}[topsep=0pt]
    354356\item
    355357\Indexc{-std=gnu11}\index{compilation option!-std=gnu11@{©-std=gnu11©}}
     
    359361Use the traditional GNU semantics for inline routines in C11 mode, which allows inline routines in header files.
    360362\end{description}
    361 The following new \CFA options are available:
    362 \begin{description}
     363
     364\CFA has the following new options:
     365\begin{description}[topsep=0pt]
    363366\item
    364367\Indexc{-CFA}\index{compilation option!-CFA@©-CFA©}
    365 Only the C preprocessor and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator.
     368Only the C preprocessor (flag ©-E©) and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator.
    366369The generated code starts with the standard \CFA \Index{prelude}.
     370
     371\item
     372\Indexc{-XCFA}\index{compilation option!-XCFA@©-XCFA©}
     373Pass next flag as-is to the ©cfa-cpp© translator (see details below).
    367374
    368375\item
    369376\Indexc{-debug}\index{compilation option!-debug@©-debug©}
    370377The program is linked with the debugging version of the runtime system.
    371 The debug version performs runtime checks to help during the debugging phase of a \CFA program, but can substantially slow program execution.
     378The debug version performs runtime checks to aid the debugging phase of a \CFA program, but can substantially slow program execution.
    372379The runtime checks should only be removed after the program is completely debugged.
    373380\textbf{This option is the default.}
     
    399406\item
    400407\Indexc{-no-include-stdhdr}\index{compilation option!-no-include-stdhdr@©-no-include-stdhdr©}
    401 Do not supply ©extern "C"© wrappers for \Celeven standard include files (see~\VRef{s:StandardHeaders}).
     408Do not supply ©extern "C"© wrappers for \Celeven standard include files \see{\VRef{s:StandardHeaders}}.
    402409\textbf{This option is \emph{not} the default.}
    403410\end{comment}
     
    430437\begin{cfa}
    431438#ifndef __CFORALL__
    432 #include <stdio.h>§\indexc{stdio.h}§ §\C{// C header file}§
     439#include <stdio.h>$\indexc{stdio.h}$ $\C{// C header file}$
    433440#else
    434 #include <fstream>§\indexc{fstream}§ §\C{// \CFA header file}§
     441#include <fstream>$\indexc{fstream}$ $\C{// \CFA header file}$
    435442#endif
    436443\end{cfa}
     
    438445
    439446The \CFA translator has multiple steps.
    440 The following flags control how the tranlator works, the stages run, and printing within a stage.
     447The following flags control how the translator works, the stages run, and printing within a stage.
    441448The majority of these flags are used by \CFA developers, but some are occasionally useful to programmers.
     449Each option must be escaped with \Indexc{-XCFA}\index{translator option!-XCFA@{©-XCFA©}} to direct it to the compiler step, similar to the ©-Xlinker© flag for the linker, \eg:
     450\begin{lstlisting}[language=sh]
     451cfa $test$.cfa -CFA -XCFA -p # print translated code without printing the standard prelude
     452cfa $test$.cfa -XCFA -P -XCFA parse -XCFA -n # show program parse without prelude
     453\end{lstlisting}
    442454\begin{description}[topsep=5pt,itemsep=0pt,parsep=0pt]
    443455\item
    444 \Indexc{-h}\index{translator option!-h@{©-h©}}, \Indexc{--help}\index{translator option!--help@{©--help©}} \, print help message
    445 \item
    446 \Indexc{-l}\index{translator option!-l@{©-l©}}, \Indexc{--libcfa}\index{translator option!--libcfa@{©--libcfa©}} \, generate libcfa.c
     456\Indexc{-c}\index{translator option!-c@{©-c©}}, \Indexc{--colors}\index{translator option!--colors@{©--colors©}} \, diagnostic color: ©never©, ©always©, \lstinline[deletekeywords=auto]{auto}
     457\item
     458\Indexc{-g}\index{translator option!-g@{©-g©}}, \Indexc{--gdb}\index{translator option!--gdb@{©--gdb©}} \, wait for gdb to attach
     459\item
     460\Indexc{-h}\index{translator option!-h@{©-h©}}, \Indexc{--help}\index{translator option!--help@{©--help©}} \, print translator help message
     461\item
     462\Indexc{-l}\index{translator option!-l@{©-l©}}, \Indexc{--libcfa}\index{translator option!--libcfa@{©--libcfa©}} \, generate ©libcfa.c©
    447463\item
    448464\Indexc{-L}\index{translator option!-L@{©-L©}}, \Indexc{--linemarks}\index{translator option!--linemarks@{©--linemarks©}} \, generate line marks
     
    454470\Indexc{-n}\index{translator option!-n@{©-n©}}, \Indexc{--no-prelude}\index{translator option!--no-prelude@{©--no-prelude©}} \, do not read prelude
    455471\item
    456 \Indexc{-p}\index{translator option!-p@{©-p©}}, \Indexc{--prototypes}\index{translator option!--prototypes@{©--prototypes©}} \, generate prototypes for prelude functions
     472\Indexc{-p}\index{translator option!-p@{©-p©}}, \Indexc{--prototypes}\index{translator option!--prototypes@{©--prototypes©}} \, do not generate prelude prototypes $\Rightarrow$ prelude not printed
     473\item
     474\Indexc{-d}\index{translator option!-d@{©-d©}}, \Indexc{--deterministic-out}\index{translator option!--deterministic-out@{©--deterministic-out©}} \, only print deterministic output
    457475\item
    458476\Indexc{-P}\index{translator option!-P@{©-P©}}, \Indexc{--print}\index{translator option!--print@{©--print©}} \, one of:
    459477\begin{description}[topsep=0pt,itemsep=0pt,parsep=0pt]
    460478\item
     479\Indexc{ascodegen}\index{translator option!-P@{©-P©}!©ascodegen©}\index{translator option!--print@{©-print©}!©ascodegen©} \, as codegen rather than AST
     480\item
     481\Indexc{asterr}\index{translator option!-P@{©-P©}!©asterr©}\index{translator option!--print@{©-print©}!©asterr©} \, AST on error
     482\item
     483\Indexc{declstats}\index{translator option!-P@{©-P©}!©declstats©}\index{translator option!--print@{©-print©}!©declstats©} \, code property statistics
     484\item
     485\Indexc{parse}\index{translator option!-P@{©-P©}!©parse©}\index{translator option!--print@{©-print©}!©parse©} \, yacc (parsing) debug information
     486\item
     487\Indexc{pretty}\index{translator option!-P@{©-P©}!©pretty©}\index{translator option!--print@{©-print©}!©pretty©} \, prettyprint for ©ascodegen© flag
     488\item
     489\Indexc{rproto}\index{translator option!-P@{©-P©}!©rproto©}\index{translator option!--print@{©-print©}!©rproto©} \, resolver-proto instance
     490\item
     491\Indexc{rsteps}\index{translator option!-P@{©-P©}!©rsteps©}\index{translator option!--print@{©-print©}!©rsteps©} \, resolver steps
     492\item
     493\Indexc{tree}\index{translator option!-P@{©-P©}!©tree©}\index{translator option!--print@{©-print©}!©tree©} \, parse tree
     494\item
     495\Indexc{ast}\index{translator option!-P@{©-P©}!©ast©}\index{translator option!--print@{©-print©}!©ast©} \, AST after parsing
     496\item
     497\Indexc{symevt}\index{translator option!-P@{©-P©}!©symevt©}\index{translator option!--print@{©-print©}!©symevt©} \, symbol table events
     498\item
    461499\Indexc{altexpr}\index{translator option!-P@{©-P©}!©altexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, alternatives for expressions
    462500\item
    463 \Indexc{ascodegen}\index{translator option!-P@{©-P©}!©ascodegen©}\index{translator option!--print@{©-print©}!©ascodegen©} \, as codegen rather than AST
    464 \item
    465 \Indexc{ast}\index{translator option!-P@{©-P©}!©ast©}\index{translator option!--print@{©-print©}!©ast©} \, AST after parsing
    466 \item
    467501\Indexc{astdecl}\index{translator option!-P@{©-P©}!©astdecl©}\index{translator option!--print@{©-print©}!©astdecl©} \, AST after declaration validation pass
    468502\item
    469 \Indexc{asterr}\index{translator option!-P@{©-P©}!©asterr©}\index{translator option!--print@{©-print©}!©asterr©} \, AST on error
     503\Indexc{resolver}\index{translator option!-P@{©-P©}!©resolver©}\index{translator option!--print@{©-print©}!©resolver©} \, before resolver step
    470504\item
    471505\Indexc{astexpr}\index{translator option!-P@{©-P©}!©astexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, AST after expression analysis
    472506\item
     507\Indexc{ctordtor}\index{translator option!-P@{©-P©}!©ctordtor©}\index{translator option!--print@{©-print©}!©ctordtor©} \, after ctor/dtor are replaced
     508\item
     509\Indexc{tuple}\index{translator option!-P@{©-P©}!©tuple©}\index{translator option!--print@{©-print©}!©tuple©} \, after tuple expansion
     510\item
    473511\Indexc{astgen}\index{translator option!-P@{©-P©}!©astgen©}\index{translator option!--print@{©-print©}!©astgen©} \, AST after instantiate generics
    474512\item
    475513\Indexc{box}\index{translator option!-P@{©-P©}!©box©}\index{translator option!--print@{©-print©}!©box©} \, before box step
    476514\item
    477 \Indexc{ctordtor}\index{translator option!-P@{©-P©}!©ctordtor©}\index{translator option!--print@{©-print©}!©ctordtor©} \, after ctor/dtor are replaced
    478 \item
    479515\Indexc{codegen}\index{translator option!-P@{©-P©}!©codegen©}\index{translator option!--print@{©-print©}!©codegen©} \, before code generation
    480 \item
    481 \Indexc{declstats}\index{translator option!-P@{©-P©}!©declstats©}\index{translator option!--print@{©-print©}!©declstats©} \, code property statistics
    482 \item
    483 \Indexc{parse}\index{translator option!-P@{©-P©}!©parse©}\index{translator option!--print@{©-print©}!©parse©} \, yacc (parsing) debug information
    484 \item
    485 \Indexc{pretty}\index{translator option!-P@{©-P©}!©pretty©}\index{translator option!--print@{©-print©}!©pretty©} \, prettyprint for ascodegen flag
    486 \item
    487 \Indexc{resolver}\index{translator option!-P@{©-P©}!©resolver©}\index{translator option!--print@{©-print©}!©resolver©} \, before resolver step
    488 \item
    489 \Indexc{rproto}\index{translator option!-P@{©-P©}!©rproto©}\index{translator option!--print@{©-print©}!©rproto©} \, resolver-proto instance
    490 \item
    491 \Indexc{rsteps}\index{translator option!-P@{©-P©}!©rsteps©}\index{translator option!--print@{©-print©}!©rsteps©} \, resolver steps
    492 \item
    493 \Indexc{symevt}\index{translator option!-P@{©-P©}!©symevt©}\index{translator option!--print@{©-print©}!©symevt©} \, symbol table events
    494 \item
    495 \Indexc{tree}\index{translator option!-P@{©-P©}!©tree©}\index{translator option!--print@{©-print©}!©tree©} \, parse tree
    496 \item
    497 \Indexc{tuple}\index{translator option!-P@{©-P©}!©tuple©}\index{translator option!--print@{©-print©}!©tuple©} \, after tuple expansion
    498516\end{description}
    499517\item
    500518\Indexc{--prelude-dir} <directory> \, prelude directory for debug/nodebug
    501519\item
    502 \Indexc{-S}\index{translator option!-S@{©-S©}!©counters,heap,time,all,none©}, \Indexc{--statistics}\index{translator option!--statistics@{©--statistics©}!©counters,heap,time,all,none©} <option-list> \, enable profiling information:
    503 \begin{description}[topsep=0pt,itemsep=0pt,parsep=0pt]
    504 \item
    505 \Indexc{counters,heap,time,all,none}
    506 \end{description}
     520\Indexc{-S}\index{translator option!-S@{©-S©}!©counters,heap,time,all,none©}, \Indexc{--statistics}\index{translator option!--statistics@{©--statistics©}!©counters,heap,time,all,none©} <option-list> \, enable profiling information: ©counters©, ©heap©, ©time©, ©all©, ©none©
    507521\item
    508522\Indexc{-t}\index{translator option!-t@{©-t©}}, \Indexc{--tree}\index{translator option!--tree@{©--tree©}} build in tree
     
    513527\label{s:BackquoteIdentifiers}
    514528
    515 \CFA introduces several new keywords (see \VRef{s:CFAKeywords}) that can clash with existing C variable-names in legacy code.
     529\CFA introduces several new keywords \see{\VRef{s:CFAKeywords}} that can clash with existing C variable-names in legacy code.
    516530Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    517531\begin{cfa}
    518 int ®``®otype = 3; §\C{// make keyword an identifier}§
    519 double ®``®forall = 3.5;
     532int @``@otype = 3; $\C{// make keyword an identifier}$
     533double @``@forall = 3.5;
    520534\end{cfa}
    521535
    522536Existing C programs with keyword clashes can be converted by enclosing keyword identifiers in backquotes, and eventually the identifier name can be changed to a non-keyword name.
    523 \VRef[Figure]{f:HeaderFileInterposition} shows how clashes in existing C header-files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©.
     537\VRef[Figure]{f:HeaderFileInterposition} shows how clashes in existing C header-files \see{\VRef{s:StandardHeaders}} can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©.
    524538Several common C header-files with keyword clashes are fixed in the standard \CFA header-library, so there is a seamless programming-experience.
    525539
     
    527541\begin{cfa}
    528542// include file uses the CFA keyword "with".
    529 #if ! defined( with ) §\C{// nesting ?}§
    530 #define with ®``®with §\C{// make keyword an identifier}§
     543#if ! defined( with )                                                   $\C{// nesting ?}$
     544#define with @``@with                                                   $\C{// make keyword an identifier}$
    531545#define __CFA_BFD_H__
    532546#endif
    533 §{\color{red}\#\textbf{include\_next} <bfdlink.h>}§ §\C{// must have internal check for multiple expansion}§
    534 #if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§
     547$\R{\#include\_next} <bfdlink.h>$                               $\C{// must have internal check for multiple expansion}$
     548#if defined( with ) && defined( __CFA_BFD_H__ ) $\C{// reset only if set}$
    535549#undef with
    536550#undef __CFA_BFD_H__
     
    544558\section{Constant Underscores}
    545559
    546 Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore}, \eg:
    547 \begin{cfa}
    548 2®_®147®_®483®_®648; §\C{// decimal constant}§
    549 56®_®ul; §\C{// decimal unsigned long constant}§
    550 0®_®377; §\C{// octal constant}§
    551 0x®_®ff®_®ff; §\C{// hexadecimal constant}§
    552 0x®_®ef3d®_®aa5c; §\C{// hexadecimal constant}§
    553 3.141®_®592®_®654; §\C{// floating constant}§
    554 10®_®e®_®+1®_®00; §\C{// floating constant}§
    555 0x®_®ff®_®ff®_®p®_®3; §\C{// hexadecimal floating}§
    556 0x®_®1.ffff®_®ffff®_®p®_®128®_®l; §\C{// hexadecimal floating long constant}§
    557 L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§; §\C{// wide character constant}§
     560Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore} as a separator, \eg:
     561\begin{cfa}
     5622@_@147@_@483@_@648; $\C{// decimal constant}$
     56356@_@ul; $\C{// decimal unsigned long constant}$
     5640@_@377; $\C{// octal constant}$
     5650x@_@ff@_@ff; $\C{// hexadecimal constant}$
     5660x@_@ef3d@_@aa5c; $\C{// hexadecimal constant}$
     5673.141@_@592@_@654; $\C{// floating constant}$
     56810@_@e@_@+1@_@00; $\C{// floating constant}$
     5690x@_@ff@_@ff@_@p@_@3; $\C{// hexadecimal floating}$
     5700x@_@1.ffff@_@ffff@_@p@_@128@_@l; $\C{// hexadecimal floating long constant}$
     571L@_@$"\texttt{\textbackslash{x}}$@_@$\texttt{ff}$@_@$\texttt{ee}"$; $\C{// wide character constant}$
    558572\end{cfa}
    559573The rules for placement of underscores are:
     
    574588It is significantly easier to read and enter long constants when they are broken up into smaller groupings (many cultures use comma and/or period among digits for the same purpose).
    575589This extension is backwards compatible, matches with the use of underscore in variable names, and appears in \Index*{Ada} and \Index*{Java} 8.
     590\CC uses the single quote (©'©) as a separator, restricted within a sequence of digits, \eg ©0xaa©©'©©ff©, ©3.141©©'©©592E1©©'©©1©.
    576591
    577592
    578593\section{Exponentiation Operator}
    579594
    580 C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow(x,y)}, to perform the exponentiation operation.
    581 \CFA extends the basic operators with the exponentiation operator ©?®\®?©\index{?\\?@©?®\®?©} and ©?\=?©\index{?\\=?@©®\®=?©}, as in, ©x ®\® y© and ©x ®\®= y©, which means $x^y$ and $x \leftarrow x^y$.
    582 The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©.
     595C, \CC, and Java (and other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow(x,y)}, to perform the exponentiation operation.
     596\CFA extends the basic operators with the exponentiation operator ©?©\R{©\\©}©?©\index{?\\?@©?@\@?©} and ©?©\R{©\\©}©=?©\index{?\\=?@©@\@=?©}, as in, ©x ©\R{©\\©}© y© and ©x ©\R{©\\©}©= y©, which means $x^y$ and $x \leftarrow x^y$.
     597The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©(w * (((int)x) \ ((int)y))) * z©.
    583598
    584599There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
     
    587602Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
    588603\begin{cfa}
    589 sout | 1 ®\® 0 | 1 ®\® 1 | 2 ®\® 8 | -4 ®\® 3 | 5 ®\® 3 | 5 ®\® 32 | 5L ®\® 32 | 5L ®\® 64 | -4 ®\® -3 | -4.0 ®\® -3 | 4.0 ®\® 2.1
    590            | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
    591 1 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
     604sout | 1 @\@ 0 | 1 @\@ 1 | 2 @\@ 8 | -4 @\@ 3 | 5 @\@ 3 | 5 @\@ 32 | 5L @\@ 32 | 5L @\@ 64 | -4 @\@ -3 | -4.0 @\@ -3 | 4.0 @\@ 2.1
     605           | (1.0f+2.0fi) @\@ (3.0f+2.0fi);
     6061 1 256 -64 125 @0@ 3273344365508751233 @0@ @0@ -0.015625 18.3791736799526 0.264715-1.1922i
    592607\end{cfa}
    593608Note, ©5 \ 32© and ©5L \ 64© overflow, and ©-4 \ -3© is a fraction but stored in an integer so all three computations generate an integral zero.
    594 Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
     609Because exponentiation has higher priority than ©+©, parenthesis are necessary for exponentiation of \Index{complex constant}s or the expression is parsed as ©1.0f+©\R{©(©}©2.0fi \ 3.0f©\R{©)©}©+2.0fi©, requiring \R{©(©}©1.0f+2.0fi©\R{©)©}© \ ©\R{©(©}©3.0f+2.0fi©\R{©)©}.
     610
    595611The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
    596612\begin{cfa}
    597 forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
    598 OT ?®\®?( OT ep, unsigned int y );
    599 forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
    600 OT ?®\®?( OT ep, unsigned long int y );
     613forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
     614T ?@\@?( T ep, unsigned int y );
     615forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
     616T ?@\@?( T ep, unsigned long int y );
    601617\end{cfa}
    602618The user type ©T© must define multiplication, one (©1©), and ©*©.
     
    609625
    610626%\subsection{\texorpdfstring{\protect\lstinline@if@/\protect\lstinline@while@ Statement}{if Statement}}
    611 \subsection{\texorpdfstring{\LstKeywordStyle{if}/\LstKeywordStyle{while} Statement}{if/while Statement}}
    612 
    613 The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.
    614 (Does not make sense for ©do©-©while©.)
    615 \begin{cfa}
    616 if ( ®int x = f()® ) ... §\C{// x != 0}§
    617 if ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
    618 if ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
    619 if ( ®struct S { int i; } x = { f() }; x.i < 4® ) §\C{// relational expression}§
    620 
    621 while ( ®int x = f()® ) ... §\C{// x != 0}§
    622 while ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
    623 while ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
    624 while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}§
    625 \end{cfa}
    626 Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if©/©while© expression, and the results are combined using the logical ©&&© operator.\footnote{\CC only provides a single declaration always compared not equal to 0.}
    627 The scope of the declaration(s) is local to the @if@ statement but exist within both the ``then'' and ``else'' clauses.
     627\subsection{\texorpdfstring{\LstKeywordStyle{if} / \LstKeywordStyle{while} Statement}{if / while Statement}}
     628
     629The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.\footnote{
     630Declarations in the ©do©-©while© condition are not useful because they appear after the loop body.}
     631\begin{cfa}
     632if ( @int x = f()@ ) ... $\C{// x != 0}$
     633if ( @int x = f(), y = g()@ ) ... $\C{// x != 0 \&\& y != 0}$
     634if ( @int x = f(), y = g(); x < y@ ) ... $\C{// relational expression}$
     635if ( @struct S { int i; } x = { f() }; x.i < 4@ ) $\C{// relational expression}$
     636
     637while ( @int x = f()@ ) ... $\C{// x != 0}$
     638while ( @int x = f(), y = g()@ ) ... $\C{// x != 0 \&\& y != 0}$
     639while ( @int x = f(), y = g(); x < y@ ) ... $\C{// relational expression}$
     640while ( @struct S { int i; } x = { f() }; x.i < 4@ ) ... $\C{// relational expression}$
     641\end{cfa}
     642Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if©/©while© expression, and the results are combined using the logical ©&&© operator.
     643The scope of the declaration(s) is local to the ©if© statement but exist within both the \emph{then} and \emph{else} clauses.
     644\CC only provides a single declaration always compared ©!=© to 0.
    628645
    629646
    630647%\section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}}
    631648\subsection{\texorpdfstring{\LstKeywordStyle{case} Clause}{case Clause}}
     649\label{s:caseClause}
    632650
    633651C restricts the ©case© clause of a ©switch© statement to a single value.
     
    640658\begin{cfa}
    641659switch ( i ) {
    642   case ®1, 3, 5®:
     660  case @1, 3, 5@:
    643661        ...
    644   case ®2, 4, 6®:
     662  case @2, 4, 6@:
    645663        ...
    646664}
     
    670688\begin{cfa}
    671689switch ( i ) {
    672   case ®1~5:® §\C{// 1, 2, 3, 4, 5}§
     690  case @1~5:@ $\C{// 1, 2, 3, 4, 5}$
    673691        ...
    674   case ®10~15:® §\C{// 10, 11, 12, 13, 14, 15}§
     692  case @10~15:@ $\C{// 10, 11, 12, 13, 14, 15}$
    675693        ...
    676694}
     
    678696Lists of subranges are also allowed.
    679697\begin{cfa}
    680 case ®1~5, 12~21, 35~42®:
     698case @1~5, 12~21, 35~42@:
    681699\end{cfa}
    682700
     
    722740if ( argc == 3 ) {
    723741        // open output file
    724         ®// open input file
    725 ®} else if ( argc == 2 ) {
    726         ®// open input file (duplicate)
    727 
    728 ®} else {
     742        @// open input file
     743@} else if ( argc == 2 ) {
     744        @// open input file (duplicate)
     745
     746@} else {
    729747        // usage message
    730748}
     
    733751\end{cquote}
    734752In this example, case 2 is always done if case 3 is done.
    735 This control flow is difficult to simulate with if statements or a ©switch© statement without fall-through as code must be duplicated or placed in a separate routine.
     753This control flow is difficult to simulate with ©if© statements or a ©switch© statement without fall-through as code must be duplicated or placed in a separate routine.
    736754C also uses fall-through to handle multiple case-values resulting in the same action:
    737755\begin{cfa}
    738756switch ( i ) {
    739   ®case 1: case 3: case 5:®     // odd values
     757  @case 1: case 3: case 5:@     // odd values
    740758        // odd action
    741759        break;
    742   ®case 2: case 4: case 6:®     // even values
     760  @case 2: case 4: case 6:@     // even values
    743761        // even action
    744762        break;
    745763}
    746764\end{cfa}
    747 However, this situation is handled in other languages without fall-through by allowing a list of case values.
    748 While fall-through itself is not a problem, the problem occurs when fall-through is the default, as this semantics is unintuitive to many programmers and is different from virtually all other programming languages with a ©switch© statement.
     765This situation better handled without fall-through by allowing a list of case values \see{\VRef{s:caseClause}}.
     766While fall-through itself is not a problem, the problem occurs when fall-through is the default, as this semantics is unintuitive to many programmers and is different from most programming languages with a ©switch© statement.
    749767Hence, default fall-through semantics results in a large number of programming errors as programmers often \emph{forget} the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.
    750768
     
    756774        if ( j < k ) {
    757775                ...
    758           ®case 1:®             // transfer into "if" statement
     776          @case 1:@             // transfer into "if" statement
    759777                ...
    760778        } // if
     
    762780        while ( j < 5 ) {
    763781                ...
    764           ®case 3:®             // transfer into "while" statement
     782          @case 3:@             // transfer into "while" statement
    765783                ...
    766784        } // while
    767785} // switch
    768786\end{cfa}
    769 The problem with this usage is branching into control structures, which is known to cause both comprehension and technical difficulties.
    770 The comprehension problem occurs from the inability to determine how control reaches a particular point due to the number of branches leading to it.
     787This usage branches into control structures, which is known to cause both comprehension and technical difficulties.
     788The comprehension problem results from the inability to determine how control reaches a particular point due to the number of branches leading to it.
    771789The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
    772 There are no positive arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
     790There are few arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
    773791Nevertheless, C does have an idiom where this capability is used, known as ``\Index*{Duff's device}''~\cite{Duff83}:
    774792\begin{cfa}
     
    794812\item
    795813It is possible to place the ©default© clause anywhere in the list of labelled clauses for a ©switch© statement, rather than only at the end.
    796 Virtually all programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
     814Most programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
    797815The logic for this semantics is that after checking all the ©case© clauses without success, the ©default© clause is selected;
    798816hence, physically placing the ©default© clause at the end of the ©case© clause list matches with this semantics.
     
    803821\begin{cfa}
    804822switch ( x ) {
    805         ®int y = 1;® §\C{// unreachable initialization}§
    806         ®x = 7;® §\C{// unreachable code without label/branch}§
     823        @int y = 1;@ $\C{// unreachable initialization}$
     824        @x = 7;@ $\C{// unreachable code without label/branch}$
    807825  case 0: ...
    808826        ...
    809         ®int z = 0;® §\C{// unreachable initialization, cannot appear after case}§
     827        @int z = 0;@ $\C{// unreachable initialization, cannot appear after case}$
    810828        z = 2;
    811829  case 1:
    812         ®x = z;® §\C{// without fall through, z is uninitialized}§
     830        @x = z;@ $\C{// without fall through, z is uninitialized}$
    813831}
    814832\end{cfa}
    815833While the declaration of the local variable ©y© is useful with a scope across all ©case© clauses, the initialization for such a variable is defined to never be executed because control always transfers over it.
    816 Furthermore, any statements before the first ©case© clause can only be executed if labelled and transferred to using a ©goto©, either from outside or inside of the ©switch©, both of which are problematic.
    817 As well, the declaration of ©z© cannot occur after the ©case© because a label can only be attached to a statement, and without a fall through to case 3, ©z© is uninitialized.
    818 The key observation is that the ©switch© statement branches into control structure, \ie there are multiple entry points into its statement body.
     834Furthermore, any statements before the first ©case© clause can only be executed if labelled and transferred to using a ©goto©, either from outside or inside of the ©switch©, where both are problematic.
     835As well, the declaration of ©z© cannot occur after the ©case© because a label can only be attached to a statement, and without a fall-through to case 3, ©z© is uninitialized.
     836The key observation is that the ©switch© statement branches into a control structure, \ie there are multiple entry points into its statement body.
    819837\end{enumerate}
    820838
     
    842860Therefore, to preserve backwards compatibility, it is necessary to introduce a new kind of ©switch© statement, called ©choose©, with no implicit fall-through semantics and an explicit fall-through if the last statement of a case-clause ends with the new keyword ©fallthrough©/©fallthru©, \eg:
    843861\begin{cfa}
    844 ®choose® ( i ) {
     862@choose@ ( i ) {
    845863  case 1:  case 2:  case 3:
    846864        ...
    847         ®// implicit end of switch (break)
    848   ®case 5:
     865        @// implicit end of switch (break)
     866  @case 5:
    849867        ...
    850         ®fallthru®; §\C{// explicit fall through}§
     868        @fallthru@; $\C{// explicit fall through}$
    851869  case 7:
    852870        ...
    853         ®break® §\C{// explicit end of switch (redundant)}§
     871        @break@ $\C{// explicit end of switch (redundant)}$
    854872  default:
    855873        j = 3;
    856874}
    857875\end{cfa}
    858 Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses;
     876Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses.
    859877An implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.
    860878An explicit ©fallthru© is retained because it is a C-idiom most C programmers expect, and its absence might discourage programmers from using the ©choose© statement.
     
    872890\begin{cfa}
    873891switch ( x ) {
    874         ®int i = 0;® §\C{// allowed only at start}§
     892        @int i = 0;@ $\C{// allowed only at start}$
    875893  case 0:
    876894        ...
    877         ®int j = 0;® §\C{// disallowed}§
     895        @int j = 0;@ $\C{// disallowed}$
    878896  case 1:
    879897        {
    880                 ®int k = 0;® §\C{// allowed at different nesting levels}§
     898                @int k = 0;@ $\C{// allowed at different nesting levels}$
    881899                ...
    882           ®case 2:® §\C{// disallow case in nested statements}§
     900          @case 2:@ $\C{// disallow case in nested statements}$
    883901        }
    884902  ...
     
    897915  case 3:
    898916        if ( ... ) {
    899                 ... ®fallthru;® // goto case 4
     917                ... @fallthru;@ // goto case 4
    900918        } else {
    901919                ...
     
    912930choose ( ... ) {
    913931  case 3:
    914         ... ®fallthrough common;®
     932        ... @fallthrough common;@
    915933  case 4:
    916         ... ®fallthrough common;®
    917 
    918   ®common:® // below fallthrough
     934        ... @fallthrough common;@
     935
     936  @common:@ // below fallthrough
    919937                          // at case-clause level
    920938        ...     // common code for cases 3/4
     
    932950                for ( ... ) {
    933951                        // multi-level transfer
    934                         ... ®fallthru common;®
     952                        ... @fallthru common;@
    935953                }
    936954                ...
    937955        }
    938956        ...
    939   ®common:® // below fallthrough
     957  @common:@ // below fallthrough
    940958                          // at case-clause level
    941959\end{cfa}
     
    948966
    949967\begin{figure}
    950 \begin{tabular}{@{}l|l@{}}
    951 \multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
     968\begin{tabular}{@{}l@{\hspace{25pt}}|l@{}}
     969\multicolumn{1}{@{}c@{\hspace{25pt}}|}{loop control} & \multicolumn{1}{c@{}}{output} \\
    952970\hline
    953 \begin{cfa}[xleftmargin=0pt]
    954 while ®()® { sout | "empty"; break; }
    955 do { sout | "empty"; break; } while ®()®;
    956 for ®()® { sout | "empty"; break; }
    957 for ( ®0® ) { sout | "A"; } sout | "zero";
    958 for ( ®1® ) { sout | "A"; }
    959 for ( ®10® ) { sout | "A"; }
    960 for ( ®= 10® ) { sout | "A"; }
    961 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
    962 for ( ®10 -~= 1 ~ 2® ) { sout | "C"; }
    963 for ( ®0.5 ~ 5.5® ) { sout | "D"; }
    964 for ( ®5.5 -~ 0.5® ) { sout | "E"; }
    965 for ( ®i; 10® ) { sout | i; }
    966 for ( ®i; = 10® ) { sout | i; }
    967 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
    968 for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; }
    969 for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
    970 for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
    971 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
    972 for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; }
     971\begin{cfa}
     972while @()@ { sout | "empty"; break; }
     973do { sout | "empty"; break; } while @()@;
     974for @()@ { sout | "empty"; break; }
     975for ( @0@ ) { sout | "A"; } sout | "zero";
     976for ( @1@ ) { sout | "A"; }
     977for ( @10@ ) { sout | "A"; }
     978for ( @= 10@ ) { sout | "A"; }
     979for ( @1 ~= 10 ~ 2@ ) { sout | "B"; }
     980for ( @10 -~= 1 ~ 2@ ) { sout | "C"; }
     981for ( @0.5 ~ 5.5@ ) { sout | "D"; }
     982for ( @5.5 -~ 0.5@ ) { sout | "E"; }
     983for ( @i; 10@ ) { sout | i; }
     984for ( @i; = 10@ ) { sout | i; }
     985for ( @i; 1 ~= 10 ~ 2@ ) { sout | i; }
     986for ( @i; 10 -~= 1 ~ 2@ ) { sout | i; }
     987for ( @i; 0.5 ~ 5.5@ ) { sout | i; }
     988for ( @i; 5.5 -~ 0.5@ ) { sout | i; }
     989for ( @ui; 2u ~= 10u ~ 2u@ ) { sout | ui; }
     990for ( @ui; 10u -~= 2u ~ 2u@ ) { sout | ui; }
    973991enum { N = 10 };
    974 for ( ®N® ) { sout | "N"; }
    975 for ( ®i; N® ) { sout | i; }
    976 for ( ®i; N -~ 0® ) { sout | i; }
     992for ( @N@ ) { sout | "N"; }
     993for ( @i; N@ ) { sout | i; }
     994for ( @i; N -~ 0@ ) { sout | i; }
    977995const int start = 3, comp = 10, inc = 2;
    978 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
    979 for ( i; 1 ~ ®@® ) { if ( i > 10 ) break; sout | i; }
    980 for ( i; 10 -~ ®@® ) { if ( i < 0 ) break; sout | i; }
    981 for ( i; 2 ~ ®@® ~ 2 ) { if ( i > 10 ) break; sout | i; }
    982 for ( i; 2.1 ~ ®@® ~ ®@® ) { if ( i > 10.5 ) break; sout | i; i += 1.7; }
    983 for ( i; 10 -~ ®@® ~ 2 ) { if ( i < 0 ) break; sout | i; }
    984 for ( i; 12.1 ~ ®@® ~ ®@® ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; }
    985 for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
    986 for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
    987 for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
    988 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
    989 for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
    990 for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
    991 for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
    992 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
    993 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
    994 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
    995 for ( i; 5 ®:® k; 1.5 ~ @ ®:® j; -5 -~ @ ~ 2 ) { sout | i | j | k; }
     996for ( @i; start ~ comp ~ inc + 1@ ) { sout | i; }
     997for ( i; 1 ~ $\R{@}$ ) { if ( i > 10 ) break; sout | i; }
     998for ( i; 10 -~ $\R{@}$ ) { if ( i < 0 ) break; sout | i; }
     999for ( i; 2 ~ $\R{@}$ ~ 2 ) { if ( i > 10 ) break; sout | i; }
     1000for ( i; 2.1 ~ $\R{@}$ ~ $\R{@}$ ) { if ( i > 10.5 ) break; sout | i; i += 1.7; }
     1001for ( i; 10 -~ $\R{@}$ ~ 2 ) { if ( i < 0 ) break; sout | i; }
     1002for ( i; 12.1 ~ $\R{@}$ ~ $\R{@}$ ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; }
     1003for ( i; 5 @:@ j; -5 ~ $@$ ) { sout | i | j; }
     1004for ( i; 5 @:@ j; -5 -~ $@$ ) { sout | i | j; }
     1005for ( i; 5 @:@ j; -5 ~ $@$ ~ 2 ) { sout | i | j; }
     1006for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 ) { sout | i | j; }
     1007for ( i; 5 @:@ j; -5 ~ $@$ ) { sout | i | j; }
     1008for ( i; 5 @:@ j; -5 -~ $@$ ) { sout | i | j; }
     1009for ( i; 5 @:@ j; -5 ~ $@$ ~ 2 ) { sout | i | j; }
     1010for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 ) { sout | i | j; }
     1011for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 @:@ k; 1.5 ~ $@$ ) { sout | i | j | k; }
     1012for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 @:@ k; 1.5 ~ $@$ ) { sout | i | j | k; }
     1013for ( i; 5 @:@ k; 1.5 ~ $@$ @:@ j; -5 -~ $@$ ~ 2 ) { sout | i | j | k; }
    9961014\end{cfa}
    9971015&
     
    10561074\subsection{Loop Control}
    10571075
    1058 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
    1059 \begin{itemize}
     1076Looping a fixed number of times, possibly with a loop index, occurs frequently.
     1077\CFA condenses simply looping to facilitate coding speed and safety.
     1078The ©for©/©while©/©do-while© loop-control is augmented as follows \see{examples in \VRef[Figure]{f:LoopControlExamples}}:
     1079\begin{itemize}[itemsep=0pt]
     1080\item
     1081©0© is the implicit start value;
     1082\item
     1083©1© is the implicit increment value.
     1084\item
     1085The up-to range uses operator ©+=© for increment;
     1086\item
     1087The down-to range uses operator ©-=© for decrement.
    10601088\item
    10611089The loop index is polymorphic in the type of the comparison value N (when the start value is implicit) or the start value M.
     1090\begin{cfa}
     1091for ( i; @5@ )                                  $\C[2.5in]{// typeof(5) i; 5 is comparison value}$
     1092for ( i; @1.5@~5.5~0.5 )                $\C{// typeof(1.5) i; 1.5 is start value}$
     1093\end{cfa}
    10621094\item
    10631095An empty conditional implies comparison value of ©1© (true).
    1064 \item
    1065 A comparison N is implicit up-to exclusive range [0,N©®)®©.
    1066 \item
    1067 A comparison ©=© N is implicit up-to inclusive range [0,N©®]®©.
    1068 \item
    1069 The up-to range M ©~©\index{~@©~©} N means exclusive range [M,N©®)®©.
    1070 \item
    1071 The up-to range M ©~=©\index{~=@©~=©} N means inclusive range [M,N©®]®©.
    1072 \item
    1073 The down-to range M ©-~©\index{-~@©-~©} N means exclusive range [N,M©®)®©.
    1074 \item
    1075 The down-to range M ©-~=©\index{-~=@©-~=©} N means inclusive range [N,M©®]®©.
    1076 \item
    1077 ©0© is the implicit start value;
    1078 \item
    1079 ©1© is the implicit increment value.
    1080 \item
    1081 The up-to range uses operator ©+=© for increment;
    1082 \item
    1083 The down-to range uses operator ©-=© for decrement.
     1096\begin{cfa}
     1097while ( $\R{/*empty*/}$ )               $\C{// while ( true )}$
     1098for ( $\R{/*empty*/}$ )                 $\C{// for ( ; true; )}$
     1099do ... while ( $\R{/*empty*/}$ ) $\C{// do ... while ( true )}$
     1100\end{cfa}
     1101\item
     1102A comparison N is implicit up-to exclusive range [0,N\R{)}.
     1103\begin{cfa}
     1104for ( @5@ )                                             $\C{// for ( typeof(5) i; i < 5; i += 1 )}$
     1105\end{cfa}
     1106\item
     1107A comparison ©=© N is implicit up-to inclusive range [0,N\R{]}.
     1108\begin{cfa}
     1109for ( @=@5 )                                    $\C{// for ( typeof(5) i; i <= 5; i += 1 )}$
     1110\end{cfa}
     1111\item
     1112The up-to range M ©~©\index{~@©~©} N means exclusive range [M,N\R{)}.
     1113\begin{cfa}
     1114for ( 1@~@5 )                                   $\C{// for ( typeof(1) i = 1; i < 5; i += 1 )}$
     1115\end{cfa}
     1116\item
     1117The up-to range M ©~=©\index{~=@©~=©} N means inclusive range [M,N\R{]}.
     1118\begin{cfa}
     1119for ( 1@~=@5 )                                  $\C{// for ( typeof(1) i = 1; i <= 5; i += 1 )}$
     1120\end{cfa}
     1121\item
     1122The down-to range M ©-~©\index{-~@©-~©} N means exclusive range [N,M\R{)}.
     1123\begin{cfa}
     1124for ( 1@-~@5 )                                  $\C{// for ( typeof(1) i = 5; i > 0; i -= 1 )}$
     1125\end{cfa}
     1126\item
     1127The down-to range M ©-~=©\index{-~=@©-~=©} N means inclusive range [N,M\R{]}.
     1128\begin{cfa}
     1129for ( 1@-~=@5 )                                 $\C{// for ( typeof(1) i = 5; i >= 0; i -= 1 )}$
     1130\end{cfa}
    10841131\item
    10851132©@© means put nothing in this field.
     1133\begin{cfa}
     1134for ( 1~$\R{@}$~2 )                             $\C{// for ( typeof(1) i = 1; /*empty*/; i += 2 )}$
     1135\end{cfa}
    10861136\item
    10871137©:© means start another index.
     1138\begin{cfa}
     1139for ( i; 5 @:@ j; 2~12~3 )              $\C{// for ( typeof(i) i = 1, j = 2; i < 5 \&\& j < 12; i += 1, j += 3 )}\CRT$
     1140\end{cfa}
    10881141\end{itemize}
    10891142
     
    11041157\begin{lrbox}{\myboxA}
    11051158\begin{cfa}[tabsize=3]
    1106 ®Compound:® {
    1107         ®Try:® try {
    1108                 ®For:® for ( ... ) {
    1109                         ®While:® while ( ... ) {
    1110                                 ®Do:® do {
    1111                                         ®If:® if ( ... ) {
    1112                                                 ®Switch:® switch ( ... ) {
     1159@Compound:@ {
     1160        @Try:@ try {
     1161                @For:@ for ( ... ) {
     1162                        @While:@ while ( ... ) {
     1163                                @Do:@ do {
     1164                                        @If:@ if ( ... ) {
     1165                                                @Switch:@ switch ( ... ) {
    11131166                                                        case 3:
    1114                                                                 ®break Compound®;
    1115                                                                 ®break Try®;
    1116                                                                 ®break For®;      /* or */  ®continue For®;
    1117                                                                 ®break While®;  /* or */  ®continue While®;
    1118                                                                 ®break Do®;      /* or */  ®continue Do®;
    1119                                                                 ®break If®;
    1120                                                                 ®break Switch®;
     1167                                                                @break Compound@;
     1168                                                                @break Try@;
     1169                                                                @break For@;      /* or */  @continue For@;
     1170                                                                @break While@;  /* or */  @continue While@;
     1171                                                                @break Do@;      /* or */  @continue Do@;
     1172                                                                @break If@;
     1173                                                                @break Switch@;
    11211174                                                        } // switch
    11221175                                                } else {
    1123                                                         ... ®break If®; ...     // terminate if
     1176                                                        ... @break If@; ...     // terminate if
    11241177                                                } // if
    11251178                                } while ( ... ); // do
    11261179                        } // while
    11271180                } // for
    1128         } ®finally® { // always executed
     1181        } @finally@ { // always executed
    11291182        } // try
    11301183} // compound
     
    11361189{
    11371190
    1138                 ®ForC:® for ( ... ) {
    1139                         ®WhileC:® while ( ... ) {
    1140                                 ®DoC:® do {
     1191                @ForC:@ for ( ... ) {
     1192                        @WhileC:@ while ( ... ) {
     1193                                @DoC:@ do {
    11411194                                        if ( ... ) {
    11421195                                                switch ( ... ) {
    11431196                                                        case 3:
    1144                                                                 ®goto Compound®;
    1145                                                                 ®goto Try®;
    1146                                                                 ®goto ForB®;      /* or */  ®goto ForC®;
    1147                                                                 ®goto WhileB®;  /* or */  ®goto WhileC®;
    1148                                                                 ®goto DoB®;      /* or */  ®goto DoC®;
    1149                                                                 ®goto If®;
    1150                                                                 ®goto Switch®;
    1151                                                         } ®Switch:® ;
     1197                                                                @goto Compound@;
     1198                                                                @goto Try@;
     1199                                                                @goto ForB@;      /* or */  @goto ForC@;
     1200                                                                @goto WhileB@;  /* or */  @goto WhileC@;
     1201                                                                @goto DoB@;      /* or */  @goto DoC@;
     1202                                                                @goto If@;
     1203                                                                @goto Switch@;
     1204                                                        } @Switch:@ ;
    11521205                                                } else {
    1153                                                         ... ®goto If®; ...      // terminate if
    1154                                                 } ®If:®;
    1155                                 } while ( ... ); ®DoB:® ;
    1156                         } ®WhileB:® ;
    1157                 } ®ForB:® ;
    1158 
    1159 
    1160 } ®Compound:® ;
     1206                                                        ... @goto If@; ...      // terminate if
     1207                                                } @If:@;
     1208                                } while ( ... ); @DoB:@ ;
     1209                        } @WhileB:@ ;
     1210                } @ForB:@ ;
     1211
     1212
     1213} @Compound:@ ;
    11611214\end{cfa}
    11621215\end{lrbox}
    11631216
     1217\hspace*{-10pt}
    11641218\subfloat[\CFA]{\label{f:CFibonacci}\usebox\myboxA}
    11651219\hspace{2pt}
    11661220\vrule
    1167 \hspace{2pt}
    11681221\subfloat[C]{\label{f:CFAFibonacciGen}\usebox\myboxB}
    11691222\caption{Multi-level Exit}
     
    11931246Grouping heterogeneous data into \newterm{aggregate}s (structure/union) is a common programming practice, and an aggregate can be further organized into more complex structures, such as arrays and containers:
    11941247\begin{cfa}
    1195 struct S { §\C{// aggregate}§
    1196         char c; §\C{// fields}§
     1248struct S { $\C{// aggregate}$
     1249        char c; $\C{// fields}$
    11971250        int i;
    11981251        double d;
     
    12031256\begin{cfa}
    12041257void f( S s ) {
    1205         ®s.®c; ®s.®i; ®s.®d; §\C{// access containing fields}§
     1258        @s.@c; @s.@i; @s.@d; $\C{// access containing fields}$
    12061259}
    12071260\end{cfa}
     
    12101263\begin{C++}
    12111264struct S {
    1212         char c; §\C{// fields}§
     1265        char c; $\C{// fields}$
    12131266        int i;
    12141267        double d;
    1215         void f() { §\C{// implicit ``this'' aggregate}§
    1216                 ®this->®c; ®this->®i; ®this->®d; §\C{// access containing fields}§
     1268        void f() { $\C{// implicit ``this'' aggregate}$
     1269                @this->@c; @this->@i; @this->@d; $\C{// access containing fields}$
    12171270        }
    12181271}
     
    12221275\begin{cfa}
    12231276struct T { double m, n; };
    1224 int S::f( T & t ) { §\C{// multiple aggregate parameters}§
    1225         c; i; d; §\C{\color{red}// this--{\textgreater}.c, this--{\textgreater}.i, this--{\textgreater}.d}§
    1226         ®t.®m; ®t.®n; §\C{// must qualify}§
    1227 }
    1228 \end{cfa}
    1229 
    1230 To simplify the programmer experience, \CFA provides a ©with© statement (see Pascal~\cite[\S~4.F]{Pascal}) to elide aggregate qualification to fields by opening a scope containing the field identifiers.
     1277int S::f( T & t ) { $\C{// multiple aggregate parameters}$
     1278        c; i; d; $\C{\R{// this--{\textgreater}c, this--{\textgreater}i, this--{\textgreater}d}}$
     1279        @t.@m; @t.@n; $\C{// must qualify}$
     1280}
     1281\end{cfa}
     1282
     1283To simplify the programmer experience, \CFA provides a ©with© statement \see{Pascal~\cite[\S~4.F]{Pascal}} to elide aggregate qualification to fields by opening a scope containing the field identifiers.
    12311284Hence, the qualified fields become variables with the side-effect that it is easier to optimizing field references in a block.
    12321285\begin{cfa}
    1233 void f( S & this ) ®with ( this )® { §\C{// with statement}§
    1234         c; i; d; §\C{\color{red}// this.c, this.i, this.d}§
     1286void f( S & this ) @with ( this )@ { $\C{// with statement}$
     1287        c; i; d; $\C{\R{// this.c, this.i, this.d}}$
    12351288}
    12361289\end{cfa}
    12371290with the generality of opening multiple aggregate-parameters:
    12381291\begin{cfa}
    1239 void f( S & s, T & t ) ®with ( s, t )® { §\C{// multiple aggregate parameters}§
    1240         c; i; d; §\C{\color{red}// s.c, s.i, s.d}§
    1241         m; n; §\C{\color{red}// t.m, t.n}§
     1292void f( S & s, T & t ) @with ( s, t )@ { $\C{// multiple aggregate parameters}$
     1293        c; i; d; $\C{\R{// s.c, s.i, s.d}}$
     1294        m; n; $\C{\R{// t.m, t.n}}$
    12421295}
    12431296\end{cfa}
     
    12451298In detail, the ©with© statement has the form:
    12461299\begin{cfa}
    1247 §\emph{with-statement}§:
    1248         'with' '(' §\emph{expression-list}§ ')' §\emph{compound-statement}§
     1300$\emph{with-statement}$:
     1301        'with' '(' $\emph{expression-list}$ ')' $\emph{compound-statement}$
    12491302\end{cfa}
    12501303and may appear as the body of a function or nested within a function body.
     
    12581311The difference between parallel and nesting occurs for fields with the same name and type:
    12591312\begin{cfa}
    1260 struct S { int ®i®; int j; double m; } s, w;
    1261 struct T { int ®i®; int k; int m; } t, w;
     1313struct S { int @i@; int j; double m; } s, w;
     1314struct T { int @i@; int k; int m; } t, w;
    12621315with ( s, t ) {
    1263         j + k; §\C{// unambiguous, s.j + t.k}§
    1264         m = 5.0; §\C{// unambiguous, t.m = 5.0}§
    1265         m = 1; §\C{// unambiguous, s.m = 1}§
    1266         int a = m; §\C{// unambiguous, a = s.i }§
    1267         double b = m; §\C{// unambiguous, b = t.m}§
    1268         int c = s.i + t.i; §\C{// unambiguous, qualification}§
    1269         (double)m; §\C{// unambiguous, cast}§
     1316        j + k; $\C{// unambiguous, s.j + t.k}$
     1317        m = 5.0; $\C{// unambiguous, t.m = 5.0}$
     1318        m = 1; $\C{// unambiguous, s.m = 1}$
     1319        int a = m; $\C{// unambiguous, a = s.i }$
     1320        double b = m; $\C{// unambiguous, b = t.m}$
     1321        int c = s.i + t.i; $\C{// unambiguous, qualification}$
     1322        (double)m; $\C{// unambiguous, cast}$
    12701323}
    12711324\end{cfa}
     
    12771330There is an interesting problem between parameters and the function-body ©with©, \eg:
    12781331\begin{cfa}
    1279 void ?{}( S & s, int i ) with ( s ) { §\C{// constructor}§
    1280         ®s.i = i;®  j = 3;  m = 5.5; §\C{// initialize fields}§
     1332void ?{}( S & s, int i ) with ( s ) { $\C{// constructor}$
     1333        @s.i = i;@  j = 3;  m = 5.5; $\C{// initialize fields}$
    12811334}
    12821335\end{cfa}
     
    12911344and implicitly opened \emph{after} a function-body open, to give them higher priority:
    12921345\begin{cfa}
    1293 void ?{}( S & s, int ®i® ) with ( s ) ®with( §\emph{\color{red}params}§ )® {
    1294         s.i = ®i®; j = 3; m = 5.5;
     1346void ?{}( S & s, int @i@ ) with ( s ) @with( $\emph{\R{params}}$ )@ {
     1347        s.i = @i@; j = 3; m = 5.5;
    12951348}
    12961349\end{cfa}
    12971350Finally, a cast may be used to disambiguate among overload variables in a ©with© expression:
    12981351\begin{cfa}
    1299 with ( w ) { ... } §\C{// ambiguous, same name and no context}§
    1300 with ( (S)w ) { ... } §\C{// unambiguous, cast}§
    1301 \end{cfa}
    1302 and ©with© expressions may be complex expressions with type reference (see Section~\ref{s:References}) to aggregate:
     1352with ( w ) { ... } $\C{// ambiguous, same name and no context}$
     1353with ( (S)w ) { ... } $\C{// unambiguous, cast}$
     1354\end{cfa}
     1355and ©with© expressions may be complex expressions with type reference \see{\VRef{s:References}} to aggregate:
    13031356% \begin{cfa}
    13041357% struct S { int i, j; } sv;
    1305 % with ( sv ) { §\C{// implicit reference}§
     1358% with ( sv ) { $\C{// implicit reference}$
    13061359%       S & sr = sv;
    1307 %       with ( sr ) { §\C{// explicit reference}§
     1360%       with ( sr ) { $\C{// explicit reference}$
    13081361%               S * sp = &sv;
    1309 %               with ( *sp ) { §\C{// computed reference}§
    1310 %                       i = 3; j = 4; §\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}§
     1362%               with ( *sp ) { $\C{// computed reference}$
     1363%                       i = 3; j = 4; $\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}$
    13111364%               }
    1312 %               i = 2; j = 3; §\C{\color{red}// sr.i, sr.j}§
     1365%               i = 2; j = 3; $\C{\color{red}// sr.i, sr.j}$
    13131366%       }
    1314 %       i = 1; j = 2; §\C{\color{red}// sv.i, sv.j}§
     1367%       i = 1; j = 2; $\C{\color{red}// sv.i, sv.j}$
    13151368% }
    13161369% \end{cfa}
     
    13201373class C {
    13211374        int i, j;
    1322         int mem() { §\C{\color{red}// implicit "this" parameter}§
    1323                 i = 1; §\C{\color{red}// this->i}§
    1324                 j = 2; §\C{\color{red}// this->j}§
     1375        int mem() { $\C{\R{// implicit "this" parameter}}$
     1376                i = 1; $\C{\R{// this->i}}$
     1377                j = 2; $\C{\R{// this->j}}$
    13251378        }
    13261379}
     
    13291382\begin{cfa}
    13301383struct S { int i, j; };
    1331 int mem( S & ®this® ) { §\C{// explicit "this" parameter}§
    1332         ®this.®i = 1; §\C{// "this" is not elided}§
    1333         ®this.®j = 2;
     1384int mem( S & @this@ ) { $\C{// explicit "this" parameter}$
     1385        @this.@i = 1; $\C{// "this" is not elided}$
     1386        @this.@j = 2;
    13341387}
    13351388\end{cfa}
    13361389but it is cumbersome having to write ``©this.©'' many times in a member.
    13371390
    1338 \CFA provides a ©with© clause/statement (see Pascal~\cite[\S~4.F]{Pascal}) to elided the "©this.©" by opening a scope containing field identifiers, changing the qualified fields into variables and giving an opportunity for optimizing qualified references.
    1339 \begin{cfa}
    1340 int mem( S & this ) ®with( this )® { §\C{// with clause}§
    1341         i = 1; §\C{\color{red}// this.i}§
    1342         j = 2; §\C{\color{red}// this.j}§
     1391\CFA provides a ©with© clause/statement \see{Pascal~\cite[\S~4.F]{Pascal}} to elided the "©this.©" by opening a scope containing field identifiers, changing the qualified fields into variables and giving an opportunity for optimizing qualified references.
     1392\begin{cfa}
     1393int mem( S & this ) @with( this )@ { $\C{// with clause}$
     1394        i = 1; $\C{\R{// this.i}}$
     1395        j = 2; $\C{\R{// this.j}}$
    13431396}
    13441397\end{cfa}
     
    13461399\begin{cfa}
    13471400struct T { double m, n; };
    1348 int mem2( S & this1, T & this2 ) ®with( this1, this2 )® {
     1401int mem2( S & this1, T & this2 ) @with( this1, this2 )@ {
    13491402        i = 1; j = 2;
    13501403        m = 1.0; n = 2.0;
     
    13571410        struct S1 { ... } s1;
    13581411        struct S2 { ... } s2;
    1359         ®with( s1 )® { §\C{// with statement}§
     1412        @with( s1 )@ { $\C{// with statement}$
    13601413                // access fields of s1 without qualification
    1361                 ®with s2® { §\C{// nesting}§
     1414                @with s2@ { $\C{// nesting}$
    13621415                        // access fields of s1 and s2 without qualification
    13631416                }
    13641417        }
    1365         ®with s1, s2® {
     1418        @with s1, s2@ {
    13661419                // access unambiguous fields of s1 and s2 without qualification
    13671420        }
     
    14141467Non-local transfer can cause stack unwinding, \ie non-local routine termination, depending on the kind of raise.
    14151468\begin{cfa}
    1416 exception_t E {}; §\C{// exception type}§
     1469exception_t E {}; $\C{// exception type}$
    14171470void f(...) {
    1418         ... throw E{}; ... §\C{// termination}§
    1419         ... throwResume E{}; ... §\C{// resumption}§
     1471        ... throw E{}; ... $\C{// termination}$
     1472        ... throwResume E{}; ... $\C{// resumption}$
    14201473}
    14211474try {
    14221475        f(...);
    1423 } catch( E e ; §boolean-predicate§ ) {          §\C{// termination handler}§
     1476} catch( E e ; $boolean-predicate$ ) {          $\C{// termination handler}$
    14241477        // recover and continue
    1425 } catchResume( E e ; §boolean-predicate§ ) { §\C{// resumption handler}§
     1478} catchResume( E e ; $boolean-predicate$ ) { $\C{// resumption handler}$
    14261479        // repair and return
    14271480} finally {
     
    14301483\end{cfa}
    14311484The kind of raise and handler match: ©throw© with ©catch© and ©throwResume© with ©catchResume©.
    1432 Then the exception type must match along with any additonal predicate must be true.
     1485Then the exception type must match along with any additional predicate must be true.
    14331486The ©catch© and ©catchResume© handlers may appear in any oder.
    14341487However, the ©finally© clause must appear at the end of the ©try© statement.
     
    14831536For example, a routine returning a \Index{pointer} to an array of integers is defined and used in the following way:
    14841537\begin{cfa}
    1485 int ®(*®f®())[®5®]® {...}; §\C{// definition}§
    1486  ... ®(*®f®())[®3®]® += 1; §\C{// usage}§
     1538int @(*@f@())[@5@]@ {...}; $\C{// definition}$
     1539 ... @(*@f@())[@3@]@ += 1; $\C{// usage}$
    14871540\end{cfa}
    14881541Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}).
     
    14991552\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    15001553\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    1501 \begin{cfa}
    1502 ß[5] *ß ®int® x1;
    1503 ß* [5]ß ®int® x2;
    1504 ß[* [5] int]ß f®( int p )®;
     1554\begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}]
     1555#[5] *# @int@ x1;
     1556#* [5]# @int@ x2;
     1557#[* [5] int]# f@( int p )@;
    15051558\end{cfa}
    15061559&
    1507 \begin{cfa}
    1508 ®int® ß*ß x1 ß[5]ß;
    1509 ®int® ß(*ßx2ß)[5]ß;
    1510 ßint (*ßf®( int p )®ß)[5]ß;
     1560\begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}]
     1561@int@ #*# x1 #[5]#;
     1562@int@ #(*#x2#)[5]#;
     1563#int (*#f@( int p )@#)[5]#;
    15111564\end{cfa}
    15121565\end{tabular}
     
    15201573\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    15211574\begin{cfa}
    1522 ®*® int x, y;
     1575@*@ int x, y;
    15231576\end{cfa}
    15241577&
    15251578\begin{cfa}
    1526 int ®*®x, ®*®y;
     1579int @*@x, @*@y;
    15271580\end{cfa}
    15281581\end{tabular}
     
    15331586\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    15341587\begin{cfa}
    1535 ®*® int x;
     1588@*@ int x;
    15361589int y;
    15371590\end{cfa}
    15381591&
    15391592\begin{cfa}
    1540 int ®*®x, y;
     1593int @*@x, y;
    15411594
    15421595\end{cfa}
     
    16471700
    16481701\section{Pointer / Reference}
     1702\label{s:PointerReference}
    16491703
    16501704C provides a \newterm{pointer type};
     
    16731727&
    16741728\begin{cfa}
    1675 int * ®const® x = (int *)100
     1729int * @const@ x = (int *)100
    16761730*x = 3;                 // implicit dereference
    1677 int * ®const® y = (int *)104;
     1731int * @const@ y = (int *)104;
    16781732*y = *x;                        // implicit dereference
    16791733\end{cfa}
     
    17131767\begin{tabular}{@{}l@{\hspace{2em}}l@{}}
    17141768\begin{cfa}
    1715 int x, y, ®*® p1, ®*® p2, ®**® p3;
    1716 p1 = ®&®x;     // p1 points to x
     1769int x, y, @*@ p1, @*@ p2, @**@ p3;
     1770p1 = @&@x;     // p1 points to x
    17171771p2 = p1;     // p2 points to x
    1718 p1 = ®&®y;     // p1 points to y
     1772p1 = @&@y;     // p1 points to y
    17191773p3 = &p2;  // p3 points to p2
    17201774\end{cfa}
     
    17281782For example, \Index*{Algol68}~\cite{Algol68} infers pointer dereferencing to select the best meaning for each pointer usage
    17291783\begin{cfa}
    1730 p2 = p1 + x; §\C{// compiler infers *p2 = *p1 + x;}§
     1784p2 = p1 + x; $\C{// compiler infers *p2 = *p1 + x;}$
    17311785\end{cfa}
    17321786Algol68 infers the following dereferencing ©*p2 = *p1 + x©, because adding the arbitrary integer value in ©x© to the address of ©p1© and storing the resulting address into ©p2© is an unlikely operation.
     
    17361790In C, objects of pointer type always manipulate the pointer object's address:
    17371791\begin{cfa}
    1738 p1 = p2; §\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}§
    1739 p2 = p1 + x; §\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}§
     1792p1 = p2; $\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}$
     1793p2 = p1 + x; $\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}$
    17401794\end{cfa}
    17411795even though the assignment to ©p2© is likely incorrect, and the programmer probably meant:
    17421796\begin{cfa}
    1743 p1 = p2; §\C{// pointer address assignment}§
    1744 ®*®p2 = ®*®p1 + x; §\C{// pointed-to value assignment / operation}§
     1797p1 = p2; $\C{// pointer address assignment}$
     1798@*@p2 = @*@p1 + x; $\C{// pointed-to value assignment / operation}$
    17451799\end{cfa}
    17461800The C semantics work well for situations where manipulation of addresses is the primary meaning and data is rarely accessed, such as storage management (©malloc©/©free©).
     
    17581812To support this common case, a reference type is introduced in \CFA, denoted by ©&©, which is the opposite dereference semantics to a pointer type, making the value at the pointed-to location the implicit semantics for dereferencing (similar but not the same as \CC \Index{reference type}s).
    17591813\begin{cfa}
    1760 int x, y, ®&® r1, ®&® r2, ®&&® r3;
    1761 ®&®r1 = &x; §\C{// r1 points to x}§
    1762 ®&®r2 = &r1; §\C{// r2 points to x}§
    1763 ®&®r1 = &y; §\C{// r1 points to y}§
    1764 ®&&®r3 = ®&®&r2; §\C{// r3 points to r2}§
    1765 r2 = ((r1 + r2) * (r3 - r1)) / (r3 - 15); §\C{// implicit dereferencing}§
     1814int x, y, @&@ r1, @&@ r2, @&&@ r3;
     1815@&@r1 = &x; $\C{// r1 points to x}$
     1816@&@r2 = &r1; $\C{// r2 points to x}$
     1817@&@r1 = &y; $\C{// r1 points to y}$
     1818@&&@r3 = @&@&r2; $\C{// r3 points to r2}$
     1819r2 = ((r1 + r2) * (r3 - r1)) / (r3 - 15); $\C{// implicit dereferencing}$
    17661820\end{cfa}
    17671821Except for auto-dereferencing by the compiler, this reference example is the same as the previous pointer example.
     
    17691823One way to conceptualize a reference is via a rewrite rule, where the compiler inserts a dereference operator before the reference variable for each reference qualifier in a declaration, so the previous example becomes:
    17701824\begin{cfa}
    1771 ®*®r2 = ((®*®r1 + ®*®r2) ®*® (®**®r3 - ®*®r1)) / (®**®r3 - 15);
     1825@*@r2 = ((@*@r1 + @*@r2) @*@ (@**@r3 - @*@r1)) / (@**@r3 - 15);
    17721826\end{cfa}
    17731827When a reference operation appears beside a dereference operation, \eg ©&*©, they cancel out.
     
    17781832For a \CFA reference type, the cancellation on the left-hand side of assignment leaves the reference as an address (\Index{lvalue}):
    17791833\begin{cfa}
    1780 (&®*®)r1 = &x; §\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}§
     1834(&@*@)r1 = &x; $\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}$
    17811835\end{cfa}
    17821836Similarly, the address of a reference can be obtained for assignment or computation (\Index{rvalue}):
    17831837\begin{cfa}
    1784 (&(&®*®)®*®)r3 = &(&®*®)r2; §\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}§
     1838(&(&@*@)@*@)r3 = &(&@*@)r2; $\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}$
    17851839\end{cfa}
    17861840Cancellation\index{cancellation!pointer/reference}\index{pointer!cancellation} works to arbitrary depth.
     
    17901844int x, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    17911845                 &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    1792 ***p3 = 3; §\C{// change x}§
    1793 r3 = 3; §\C{// change x, ***r3}§
    1794 **p3 = ...; §\C{// change p1}§
    1795 &r3 = ...; §\C{// change r1, (\&*)**r3, 1 cancellation}§
    1796 *p3 = ...; §\C{// change p2}§
    1797 &&r3 = ...; §\C{// change r2, (\&(\&*)*)*r3, 2 cancellations}§
    1798 &&&r3 = p3; §\C{// change r3 to p3, (\&(\&(\&*)*)*)r3, 3 cancellations}§
     1846***p3 = 3; $\C{// change x}$
     1847r3 = 3; $\C{// change x, ***r3}$
     1848**p3 = ...; $\C{// change p1}$
     1849&r3 = ...; $\C{// change r1, (\&*)**r3, 1 cancellation}$
     1850*p3 = ...; $\C{// change p2}$
     1851&&r3 = ...; $\C{// change r2, (\&(\&*)*)*r3, 2 cancellations}$
     1852&&&r3 = p3; $\C{// change r3 to p3, (\&(\&(\&*)*)*)r3, 3 cancellations}$
    17991853\end{cfa}
    18001854Furthermore, both types are equally performant, as the same amount of dereferencing occurs for both types.
     
    18031857As for a pointer type, a reference type may have qualifiers:
    18041858\begin{cfa}
    1805 const int cx = 5; §\C{// cannot change cx;}§
    1806 const int & cr = cx; §\C{// cannot change what cr points to}§
    1807 ®&®cr = &cx; §\C{// can change cr}§
    1808 cr = 7; §\C{// error, cannot change cx}§
    1809 int & const rc = x; §\C{// must be initialized}§
    1810 ®&®rc = &x; §\C{// error, cannot change rc}§
    1811 const int & const crc = cx; §\C{// must be initialized}§
    1812 crc = 7; §\C{// error, cannot change cx}§
    1813 ®&®crc = &cx; §\C{// error, cannot change crc}§
     1859const int cx = 5; $\C{// cannot change cx;}$
     1860const int & cr = cx; $\C{// cannot change what cr points to}$
     1861@&@cr = &cx; $\C{// can change cr}$
     1862cr = 7; $\C{// error, cannot change cx}$
     1863int & const rc = x; $\C{// must be initialized}$
     1864@&@rc = &x; $\C{// error, cannot change rc}$
     1865const int & const crc = cx; $\C{// must be initialized}$
     1866crc = 7; $\C{// error, cannot change cx}$
     1867@&@crc = &cx; $\C{// error, cannot change crc}$
    18141868\end{cfa}
    18151869Hence, for type ©& const©, there is no pointer assignment, so ©&rc = &x© is disallowed, and \emph{the address value cannot be the null pointer unless an arbitrary pointer is coerced\index{coercion} into the reference}:
    18161870\begin{cfa}
    1817 int & const cr = *0; §\C{// where 0 is the int * zero}§
     1871int & const cr = *0; $\C{// where 0 is the int * zero}$
    18181872\end{cfa}
    18191873Note, constant reference-types do not prevent \Index{addressing errors} because of explicit storage-management:
     
    18221876cr = 5;
    18231877free( &cr );
    1824 cr = 7; §\C{// unsound pointer dereference}§
     1878cr = 7; $\C{// unsound pointer dereference}$
    18251879\end{cfa}
    18261880
    18271881The position of the ©const© qualifier \emph{after} the pointer/reference qualifier causes confuse for C programmers.
    18281882The ©const© qualifier cannot be moved before the pointer/reference qualifier for C style-declarations;
    1829 \CFA-style declarations (see \VRef{s:AlternativeDeclarations}) attempt to address this issue:
     1883\CFA-style declarations \see{\VRef{s:AlternativeDeclarations}} attempt to address this issue:
    18301884\begin{cquote}
    18311885\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    18321886\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    18331887\begin{cfa}
    1834 ®const® * ®const® * const int ccp;
    1835 ®const® & ®const® & const int ccr;
     1888@const@ * @const@ * const int ccp;
     1889@const@ & @const@ & const int ccr;
    18361890\end{cfa}
    18371891&
    18381892\begin{cfa}
    1839 const int * ®const® * ®const® ccp;
     1893const int * @const@ * @const@ ccp;
    18401894
    18411895\end{cfa}
     
    18461900Finally, like pointers, references are usable and composable with other type operators and generators.
    18471901\begin{cfa}
    1848 int w, x, y, z, & ar[3] = { x, y, z }; §\C{// initialize array of references}§
    1849 &ar[1] = &w; §\C{// change reference array element}§
    1850 typeof( ar[1] ) p; §\C{// (gcc) is int, \ie the type of referenced object}§
    1851 typeof( &ar[1] ) q; §\C{// (gcc) is int \&, \ie the type of reference}§
    1852 sizeof( ar[1] ) == sizeof( int ); §\C{// is true, \ie the size of referenced object}§
    1853 sizeof( &ar[1] ) == sizeof( int *) §\C{// is true, \ie the size of a reference}§
     1902int w, x, y, z, & ar[3] = { x, y, z }; $\C{// initialize array of references}$
     1903&ar[1] = &w; $\C{// change reference array element}$
     1904typeof( ar[1] ) p; $\C{// (gcc) is int, \ie the type of referenced object}$
     1905typeof( &ar[1] ) q; $\C{// (gcc) is int \&, \ie the type of reference}$
     1906sizeof( ar[1] ) == sizeof( int ); $\C{// is true, \ie the size of referenced object}$
     1907sizeof( &ar[1] ) == sizeof( int *) $\C{// is true, \ie the size of a reference}$
    18541908\end{cfa}
    18551909
    18561910In contrast to \CFA reference types, \Index*[C++]{\CC{}}'s reference types are all ©const© references, preventing changes to the reference address, so only value assignment is possible, which eliminates half of the \Index{address duality}.
    18571911Also, \CC does not allow \Index{array}s\index{array!reference} of reference\footnote{
    1858 The reason for disallowing arrays of reference is unknown, but possibly comes from references being ethereal (like a textual macro), and hence, replaceable by the referant object.}
     1912The reason for disallowing arrays of reference is unknown, but possibly comes from references being ethereal (like a textual macro), and hence, replaceable by the referent object.}
    18591913\Index*{Java}'s reference types to objects (all Java objects are on the heap) are like C pointers, which always manipulate the address, and there is no (bit-wise) object assignment, so objects are explicitly cloned by shallow or deep copying, which eliminates half of the address duality.
    18601914
     
    18681922Therefore, for pointer/reference initialization, the initializing value must be an address not a value.
    18691923\begin{cfa}
    1870 int * p = &x; §\C{// assign address of x}§
    1871 ®int * p = x;® §\C{// assign value of x}§
    1872 int & r = x; §\C{// must have address of x}§
     1924int * p = &x; $\C{// assign address of x}$
     1925@int * p = x;@ $\C{// assign value of x}$
     1926int & r = x; $\C{// must have address of x}$
    18731927\end{cfa}
    18741928Like the previous example with C pointer-arithmetic, it is unlikely assigning the value of ©x© into a pointer is meaningful (again, a warning is usually given).
     
    18791933Similarly, when a reference type is used for a parameter/return type, the call-site argument does not require a reference operator for the same reason.
    18801934\begin{cfa}
    1881 int & f( int & r ); §\C{// reference parameter and return}§
    1882 z = f( x ) + f( y ); §\C{// reference operator added, temporaries needed for call results}§
     1935int & f( int & r ); $\C{// reference parameter and return}$
     1936z = f( x ) + f( y ); $\C{// reference operator added, temporaries needed for call results}$
    18831937\end{cfa}
    18841938Within routine ©f©, it is possible to change the argument by changing the corresponding parameter, and parameter ©r© can be locally reassigned within ©f©.
     
    18931947When a pointer/reference parameter has a ©const© value (immutable), it is possible to pass literals and expressions.
    18941948\begin{cfa}
    1895 void f( ®const® int & cr );
    1896 void g( ®const® int * cp );
    1897 f( 3 );                   g( ®&®3 );
    1898 f( x + y );             g( ®&®(x + y) );
     1949void f( @const@ int & cr );
     1950void g( @const@ int * cp );
     1951f( 3 );                   g( @&@3 );
     1952f( x + y );             g( @&@(x + y) );
    18991953\end{cfa}
    19001954Here, the compiler passes the address to the literal 3 or the temporary for the expression ©x + y©, knowing the argument cannot be changed through the parameter.
     
    19071961void f( int & r );
    19081962void g( int * p );
    1909 f( 3 );                   g( ®&®3 ); §\C{// compiler implicit generates temporaries}§
    1910 f( x + y );             g( ®&®(x + y) ); §\C{// compiler implicit generates temporaries}§
     1963f( 3 );                   g( @&@3 ); $\C{// compiler implicit generates temporaries}$
     1964f( x + y );             g( @&@(x + y) ); $\C{// compiler implicit generates temporaries}$
    19111965\end{cfa}
    19121966Essentially, there is an implicit \Index{rvalue} to \Index{lvalue} conversion in this case.\footnote{
     
    19191973\begin{cfa}
    19201974void f( int i );
    1921 void (* fp)( int ); §\C{// routine pointer}§
    1922 fp = f; §\C{// reference initialization}§
    1923 fp = &f; §\C{// pointer initialization}§
    1924 fp = *f; §\C{// reference initialization}§
    1925 fp(3); §\C{// reference invocation}§
    1926 (*fp)(3); §\C{// pointer invocation}§
     1975void (* fp)( int ); $\C{// routine pointer}$
     1976fp = f; $\C{// reference initialization}$
     1977fp = &f; $\C{// pointer initialization}$
     1978fp = *f; $\C{// reference initialization}$
     1979fp(3); $\C{// reference invocation}$
     1980(*fp)(3); $\C{// pointer invocation}$
    19271981\end{cfa}
    19281982While C's treatment of routine objects has similarity to inferring a reference type in initialization contexts, the examples are assignment not initialization, and all possible forms of assignment are possible (©f©, ©&f©, ©*f©) without regard for type.
    19291983Instead, a routine object should be referenced by a ©const© reference:
    19301984\begin{cfa}
    1931 ®const® void (®&® fr)( int ) = f; §\C{// routine reference}§
    1932 fr = ... §\C{// error, cannot change code}§
    1933 &fr = ...; §\C{// changing routine reference}§
    1934 fr( 3 ); §\C{// reference call to f}§
    1935 (*fr)(3); §\C{// error, incorrect type}§
     1985@const@ void (@&@ fr)( int ) = f; $\C{// routine reference}$
     1986fr = ... $\C{// error, cannot change code}$
     1987&fr = ...; $\C{// changing routine reference}$
     1988fr( 3 ); $\C{// reference call to f}$
     1989(*fr)(3); $\C{// error, incorrect type}$
    19361990\end{cfa}
    19371991because the value of the routine object is a routine literal, \ie the routine code is normally immutable during execution.\footnote{
     
    19462000\begin{itemize}
    19472001\item
    1948 if ©R© is an \Index{rvalue} of type ©T &©$_1\cdots$ ©&©$_r$, where $r \ge 1$ references (©&© symbols), than ©&R© has type ©T ®*®&©$_{\color{red}2}\cdots$ ©&©$_{\color{red}r}$, \ie ©T© pointer with $r-1$ references (©&© symbols).
    1949 
    1950 \item
    1951 if ©L© is an \Index{lvalue} of type ©T &©$_1\cdots$ ©&©$_l$, where $l \ge 0$ references (©&© symbols), than ©&L© has type ©T ®*®&©$_{\color{red}1}\cdots$ ©&©$_{\color{red}l}$, \ie ©T© pointer with $l$ references (©&© symbols).
     2002if ©R© is an \Index{rvalue} of type ©T &©$_1\cdots$ ©&©$_r$, where $r \ge 1$ references (©&© symbols), than ©&R© has type ©T ©\R{©*©}©&©\R{$_2$}$\cdots$ ©&©\R{$_r$}, \ie ©T© pointer with $r-1$ references (©&© symbols).
     2003
     2004\item
     2005if ©L© is an \Index{lvalue} of type ©T &©$_1\cdots$ ©&©$_l$, where $l \ge 0$ references (©&© symbols), than ©&L© has type ©T ©\R{©*©}©&©\R{$_1$}$\cdots$ ©&©\R{$_l$}, \ie ©T© pointer with $l$ references (©&© symbols).
    19522006\end{itemize}
    19532007The following example shows the first rule applied to different \Index{rvalue} contexts:
     
    19552009int x, * px, ** ppx, *** pppx, **** ppppx;
    19562010int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    1957 x = rrrx; §\C[2.0in]{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}§
    1958 px = &rrrx; §\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (\&x)}§
    1959 ppx = &&rrrx; §\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (\&rx)}§
    1960 pppx = &&&rrrx; §\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (\&rrx)}§
    1961 ppppx = &&&&rrrx; §\C{// starting from \&\&\&rrrx, \&\&\&\&rrrx is an rvalue with type int **** (\&rrrx)}§
     2011x = rrrx; $\C[2.0in]{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}$
     2012px = &rrrx; $\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (\&x)}$
     2013ppx = &&rrrx; $\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (\&rx)}$
     2014pppx = &&&rrrx; $\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (\&rrx)}$
     2015ppppx = &&&&rrrx; $\C{// starting from \&\&\&rrrx, \&\&\&\&rrrx is an rvalue with type int **** (\&rrrx)}$
    19622016\end{cfa}
    19632017The following example shows the second rule applied to different \Index{lvalue} contexts:
     
    19652019int x, * px, ** ppx, *** pppx;
    19662020int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    1967 rrrx = 2; §\C{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}§
    1968 &rrrx = px; §\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (rx)}§
    1969 &&rrrx = ppx; §\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (rrx)}§
    1970 &&&rrrx = pppx; §\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (rrrx)}\CRT§
     2021rrrx = 2; $\C{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}$
     2022&rrrx = px; $\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (rx)}$
     2023&&rrrx = ppx; $\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (rrx)}$
     2024&&&rrrx = pppx; $\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (rrrx)}\CRT$
    19712025\end{cfa}
    19722026
     
    19812035\begin{cfa}
    19822036int x;
    1983 x + 1; §\C[2.0in]{// lvalue variable (int) converts to rvalue for expression}§
     2037x + 1; $\C[2.0in]{// lvalue variable (int) converts to rvalue for expression}$
    19842038\end{cfa}
    19852039An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped.
     
    19912045\begin{cfa}
    19922046int x, &r = x, f( int p );
    1993 x = ®r® + f( ®r® ); §\C{// lvalue reference converts to rvalue}§
     2047x = @r@ + f( @r@ ); $\C{// lvalue reference converts to rvalue}$
    19942048\end{cfa}
    19952049An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped.
     
    19982052lvalue to reference conversion: \lstinline[deletekeywords=lvalue]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
    19992053\begin{cfa}
    2000 int x, &r = ®x®, f( int & p ); §\C{// lvalue variable (int) convert to reference (int \&)}§
    2001 f( ®x® ); §\C{// lvalue variable (int) convert to reference (int \&)}§
     2054int x, &r = @x@, f( int & p ); $\C{// lvalue variable (int) convert to reference (int \&)}$
     2055f( @x@ ); $\C{// lvalue variable (int) convert to reference (int \&)}$
    20022056\end{cfa}
    20032057Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.
     
    20092063\begin{cfa}
    20102064int x, & f( int & p );
    2011 f( ®x + 3® );   §\C[1.5in]{// rvalue parameter (int) implicitly converts to lvalue temporary reference (int \&)}§
    2012 ®&f®(...) = &x; §\C{// rvalue result (int \&) implicitly converts to lvalue temporary reference (int \&)}\CRT§
     2065f( @x + 3@ );   $\C[1.5in]{// rvalue parameter (int) implicitly converts to lvalue temporary reference (int \&)}$
     2066@&f@(...) = &x; $\C{// rvalue result (int \&) implicitly converts to lvalue temporary reference (int \&)}\CRT$
    20132067\end{cfa}
    20142068In both case, modifications to the temporary are inaccessible (\Index{warning}).
     
    21822236The point of the new syntax is to allow returning multiple values from a routine~\cite{Galletly96,CLU}, \eg:
    21832237\begin{cfa}
    2184 ®[ int o1, int o2, char o3 ]® f( int i1, char i2, char i3 ) {
    2185         §\emph{routine body}§
     2238@[ int o1, int o2, char o3 ]@ f( int i1, char i2, char i3 ) {
     2239        $\emph{routine body}$
    21862240}
    21872241\end{cfa}
     
    21942248Declaration qualifiers can only appear at the start of a routine definition, \eg:
    21952249\begin{cfa}
    2196 ®extern® [ int x ] g( int y ) {§\,§}
     2250@extern@ [ int x ] g( int y ) {$\,$}
    21972251\end{cfa}
    21982252Lastly, if there are no output parameters or input parameters, the brackets and/or parentheses must still be specified;
    21992253in both cases the type is assumed to be void as opposed to old style C defaults of int return type and unknown parameter types, respectively, as in:
    22002254\begin{cfa}
    2201 [§\,§] g(); §\C{// no input or output parameters}§
    2202 [ void ] g( void ); §\C{// no input or output parameters}§
     2255[$\,$] g(); $\C{// no input or output parameters}$
     2256[ void ] g( void ); $\C{// no input or output parameters}$
    22032257\end{cfa}
    22042258
     
    22182272\begin{cfa}
    22192273typedef int foo;
    2220 int f( int (* foo) ); §\C{// foo is redefined as a parameter name}§
     2274int f( int (* foo) ); $\C{// foo is redefined as a parameter name}$
    22212275\end{cfa}
    22222276The string ``©int (* foo)©'' declares a C-style named-parameter of type pointer to an integer (the parenthesis are superfluous), while the same string declares a \CFA style unnamed parameter of type routine returning integer with unnamed parameter of type pointer to foo.
     
    22262280C-style declarations can be used to declare parameters for \CFA style routine definitions, \eg:
    22272281\begin{cfa}
    2228 [ int ] f( * int, int * ); §\C{// returns an integer, accepts 2 pointers to integers}§
    2229 [ * int, int * ] f( int ); §\C{// returns 2 pointers to integers, accepts an integer}§
     2282[ int ] f( * int, int * ); $\C{// returns an integer, accepts 2 pointers to integers}$
     2283[ * int, int * ] f( int ); $\C{// returns 2 pointers to integers, accepts an integer}$
    22302284\end{cfa}
    22312285The reason for allowing both declaration styles in the new context is for backwards compatibility with existing preprocessor macros that generate C-style declaration-syntax, as in:
    22322286\begin{cfa}
    22332287#define ptoa( n, d ) int (*n)[ d ]
    2234 int f( ptoa( p, 5 ) ) ... §\C{// expands to int f( int (*p)[ 5 ] )}§
    2235 [ int ] f( ptoa( p, 5 ) ) ... §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§
     2288int f( ptoa( p, 5 ) ) ... $\C{// expands to int f( int (*p)[ 5 ] )}$
     2289[ int ] f( ptoa( p, 5 ) ) ... $\C{// expands to [ int ] f( int (*p)[ 5 ] )}$
    22362290\end{cfa}
    22372291Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    22522306\begin{minipage}{\linewidth}
    22532307\begin{cfa}
    2254 ®[ int x, int y ]® f() {
     2308@[ int x, int y ]@ f() {
    22552309        int z;
    22562310        ... x = 0; ... y = z; ...
    2257         ®return;® §\C{// implicitly return x, y}§
     2311        @return;@ $\C{// implicitly return x, y}$
    22582312}
    22592313\end{cfa}
     
    22652319[ int x, int y ] f() {
    22662320        ...
    2267 } §\C{// implicitly return x, y}§
     2321} $\C{// implicitly return x, y}$
    22682322\end{cfa}
    22692323In this case, the current values of ©x© and ©y© are returned to the calling routine just as if a ©return© had been encountered.
     
    22742328[ int x, int y ] f( int, x, int y ) {
    22752329        ...
    2276 } §\C{// implicitly return x, y}§
     2330} $\C{// implicitly return x, y}$
    22772331\end{cfa}
    22782332This notation allows the compiler to eliminate temporary variables in nested routine calls.
    22792333\begin{cfa}
    2280 [ int x, int y ] f( int, x, int y ); §\C{// prototype declaration}§
     2334[ int x, int y ] f( int, x, int y ); $\C{// prototype declaration}$
    22812335int a, b;
    22822336[a, b] = f( f( f( a, b ) ) );
     
    22922346as well, parameter names are optional, \eg:
    22932347\begin{cfa}
    2294 [ int x ] f (); §\C{// returning int with no parameters}§
    2295 [ * int ] g (int y); §\C{// returning pointer to int with int parameter}§
    2296 [ ] h ( int, char ); §\C{// returning no result with int and char parameters}§
    2297 [ * int, int ] j ( int ); §\C{// returning pointer to int and int, with int parameter}§
     2348[ int x ] f (); $\C{// returning int with no parameters}$
     2349[ * int ] g (int y); $\C{// returning pointer to int with int parameter}$
     2350[ ] h ( int, char ); $\C{// returning no result with int and char parameters}$
     2351[ * int, int ] j ( int ); $\C{// returning pointer to int and int, with int parameter}$
    22982352\end{cfa}
    22992353This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
    2300 Like C, it is possible to declare multiple routine-prototypes in a single declaration, where the return type is distributed across \emph{all} routine names in the declaration list (see~\VRef{s:AlternativeDeclarations}), \eg:
     2354Like C, it is possible to declare multiple routine-prototypes in a single declaration, where the return type is distributed across \emph{all} routine names in the declaration list \see{\VRef{s:AlternativeDeclarations}}, \eg:
    23012355\begin{cfa}
    23022356C :             const double bar1(), bar2( int ), bar3( double );
    2303 §\CFA§: [const double] foo(), foo( int ), foo( double ) { return 3.0; }
     2357$\CFA$: [const double] foo(), foo( int ), foo( double ) { return 3.0; }
    23042358\end{cfa}
    23052359\CFA allows the last routine in the list to define its body.
     
    23162370The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg:
    23172371\begin{cfa}
    2318 * [ int x ] () fp; §\C{// pointer to routine returning int with no parameters}§
    2319 * [ * int ] (int y) gp; §\C{// pointer to routine returning pointer to int with int parameter}§
    2320 * [ ] (int,char) hp; §\C{// pointer to routine returning no result with int and char parameters}§
    2321 * [ * int,int ] ( int ) jp; §\C{// pointer to routine returning pointer to int and int, with int parameter}§
     2372* [ int x ] () fp; $\C[2.25in]{// pointer to routine returning int with no parameters}$
     2373* [ * int ] (int y) gp; $\C{// pointer to routine returning pointer to int with int parameter}$
     2374* [ ] (int,char) hp; $\C{// pointer to routine returning no result with int and char parameters}$
     2375* [ * int,int ] ( int ) jp; $\C{// pointer to routine returning pointer to int and int, with int parameter}\CRT$
    23222376\end{cfa}
    23232377While parameter names are optional, \emph{a routine name cannot be specified};
    23242378for example, the following is incorrect:
    23252379\begin{cfa}
    2326 * [ int x ] f () fp; §\C{// routine name "f" is not allowed}§
     2380* [ int x ] f () fp; $\C{// routine name "f" is not allowed}$
    23272381\end{cfa}
    23282382
     
    23472401whereas a named (keyword) call may be:
    23482402\begin{cfa}
    2349 p( z : 3, x : 4, y : 7 );  §\C{// rewrite $\Rightarrow$ p( 4, 7, 3 )}§
     2403p( z : 3, x : 4, y : 7 );  $\C{// rewrite \(\Rightarrow\) p( 4, 7, 3 )}$
    23502404\end{cfa}
    23512405Here the order of the arguments is unimportant, and the names of the parameters are used to associate argument values with the corresponding parameters.
     
    23642418For example, the following routine prototypes and definition are all valid.
    23652419\begin{cfa}
    2366 void p( int, int, int ); §\C{// equivalent prototypes}§
     2420void p( int, int, int ); $\C{// equivalent prototypes}$
    23672421void p( int x, int y, int z );
    23682422void p( int y, int x, int z );
    23692423void p( int z, int y, int x );
    2370 void p( int q, int r, int s ) {} §\C{// match with this definition}§
     2424void p( int q, int r, int s ) {} $\C{// match with this definition}$
    23712425\end{cfa}
    23722426Forcing matching parameter names in routine prototypes with corresponding routine definitions is possible, but goes against a strong tradition in C programming.
     
    23802434int f( int x, double y );
    23812435
    2382 f( j : 3, i : 4 ); §\C{// 1st f}§
    2383 f( x : 7, y : 8.1 ); §\C{// 2nd f}§
    2384 f( 4, 5 );  §\C{// ambiguous call}§
     2436f( j : 3, i : 4 ); $\C{// 1st f}$
     2437f( x : 7, y : 8.1 ); $\C{// 2nd f}$
     2438f( 4, 5 );  $\C{// ambiguous call}$
    23852439\end{cfa}
    23862440However, named arguments compound routine resolution in conjunction with conversions:
    23872441\begin{cfa}
    2388 f( i : 3, 5.7 ); §\C{// ambiguous call ?}§
     2442f( i : 3, 5.7 ); $\C{// ambiguous call ?}$
    23892443\end{cfa}
    23902444Depending on the cost associated with named arguments, this call could be resolvable or ambiguous.
     
    24002454the allowable positional calls are:
    24012455\begin{cfa}
    2402 p(); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
    2403 p( 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
    2404 p( 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
    2405 p( 4, 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 4 )}§
     2456p(); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 3 )}$
     2457p( 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 2, 3 )}$
     2458p( 4, 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 4, 3 )}$
     2459p( 4, 4, 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 4, 4 )}$
    24062460// empty arguments
    2407 p(  , 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 4 )}§
    2408 p( 4,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 4 )}§
    2409 p( 4, 4,   ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
    2410 p( 4,  ,   ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
    2411 p(  , 4,   ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 3 )}§
    2412 p(  ,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 4 )}§
    2413 p(  ,  ,   ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
     2461p(  , 4, 4 ); $\C{// rewrite \(\Rightarrow\) p( 1, 4, 4 )}$
     2462p( 4,  , 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 2, 4 )}$
     2463p( 4, 4,   ); $\C{// rewrite \(\Rightarrow\) p( 4, 4, 3 )}$
     2464p( 4,  ,   ); $\C{// rewrite \(\Rightarrow\) p( 4, 2, 3 )}$
     2465p(  , 4,   ); $\C{// rewrite \(\Rightarrow\) p( 1, 4, 3 )}$
     2466p(  ,  , 4 ); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 4 )}$
     2467p(  ,  ,   ); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 3 )}$
    24142468\end{cfa}
    24152469Here the missing arguments are inserted from the default values in the parameter list.
     
    24352489Default values may only appear in a prototype versus definition context:
    24362490\begin{cfa}
    2437 void p( int x, int y = 2, int z = 3 ); §\C{// prototype: allowed}§
    2438 void p( int, int = 2, int = 3 ); §\C{// prototype: allowed}§
    2439 void p( int x, int y = 2, int z = 3 ) {} §\C{// definition: not allowed}§
     2491void p( int x, int y = 2, int z = 3 ); $\C{// prototype: allowed}$
     2492void p( int, int = 2, int = 3 ); $\C{// prototype: allowed}$
     2493void p( int x, int y = 2, int z = 3 ) {} $\C{// definition: not allowed}$
    24402494\end{cfa}
    24412495The reason for this restriction is to allow separate compilation.
     
    24522506\begin{cfa}
    24532507p( int x, int y, int z, ... );
    2454 p( 1, 4, 5, 6, z : 3, y : 2 ); §\C{// assume p( /* positional */, ... , /* named */ );}§
    2455 p( 1, z : 3, y : 2, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, ... );}§
     2508p( 1, 4, 5, 6, z : 3, y : 2 ); $\C{// assume p( /* positional */, ... , /* named */ );}$
     2509p( 1, z : 3, y : 2, 4, 5, 6 ); $\C{// assume p( /* positional */, /* named */, ... );}$
    24562510\end{cfa}
    24572511In the first call, it is necessary for the programmer to conceptually rewrite the call, changing named arguments into positional, before knowing where the ellipse arguments begin.
     
    24622516\begin{cfa}
    24632517void p( int x, int y = 2, int z = 3... );
    2464 p( 1, 4, 5, 6, z : 3 ); §\C{// assume p( /* positional */, ... , /* named */ );}§
    2465 p( 1, z : 3, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, ... );}§
     2518p( 1, 4, 5, 6, z : 3 ); $\C{// assume p( /* positional */, ... , /* named */ );}$
     2519p( 1, z : 3, 4, 5, 6 ); $\C{// assume p( /* positional */, /* named */, ... );}$
    24662520\end{cfa}
    24672521The first call is an error because arguments 4 and 5 are actually positional not ellipse arguments;
     
    24692523In the second call, the default value for y is implicitly inserted after argument 1 and the named arguments separate the positional and ellipse arguments, making it trivial to read the call.
    24702524For these reasons, \CFA requires named arguments before ellipse arguments.
    2471 Finally, while ellipse arguments are needed for a small set of existing C routines, like printf, the extended \CFA type system largely eliminates the need for ellipse arguments (see Section 24), making much of this discussion moot.
    2472 
    2473 Default arguments and overloading (see Section 24) are complementary.
     2525Finally, while ellipse arguments are needed for a small set of existing C routines, like ©printf©, the extended \CFA type system largely eliminates the need for ellipse arguments \see{\VRef{s:Overloading}}, making much of this discussion moot.
     2526
     2527Default arguments and overloading \see{\VRef{s:Overloading}} are complementary.
    24742528While in theory default arguments can be simulated with overloading, as in:
    24752529\begin{cquote}
     
    24932547Furthermore, overloading cannot handle accessing default arguments in the middle of a positional list, via a missing argument, such as:
    24942548\begin{cfa}
    2495 p( 1, /* default */, 5 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 5 )}§
     2549p( 1, /* default */, 5 ); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 5 )}$
    24962550\end{cfa}
    24972551
     
    25062560\begin{cfa}
    25072561struct {
    2508         int f1; §\C{// named field}§
    2509         int f2 : 4; §\C{// named field with bit field size}§
    2510         int : 3; §\C{// unnamed field for basic type with bit field size}§
    2511         int ; §\C{// disallowed, unnamed field}§
    2512         int *; §\C{// disallowed, unnamed field}§
    2513         int (*)( int ); §\C{// disallowed, unnamed field}§
     2562        int f1; $\C{// named field}$
     2563        int f2 : 4; $\C{// named field with bit field size}$
     2564        int : 3; $\C{// unnamed field for basic type with bit field size}$
     2565        int ; $\C{// disallowed, unnamed field}$
     2566        int *; $\C{// disallowed, unnamed field}$
     2567        int (*)( int ); $\C{// disallowed, unnamed field}$
    25142568};
    25152569\end{cfa}
     
    25192573\begin{cfa}
    25202574struct {
    2521         int , , ; §\C{// 3 unnamed fields}§
     2575        int , , ; $\C{// 3 unnamed fields}$
    25222576}
    25232577\end{cfa}
     
    25312585\subsection{Type Nesting}
    25322586
    2533 \CFA allows \Index{type nesting}, and type qualification of the nested types (see \VRef[Figure]{f:TypeNestingQualification}), where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
     2587\CFA allows \Index{type nesting}, and type qualification of the nested types \see{\VRef[Figure]{f:TypeNestingQualification}}, where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
    25342588\begin{figure}
    25352589\centering
     
    25872641
    25882642int fred() {
    2589         s.t.c = ®S.®R;  // type qualification
    2590         struct ®S.®T t = { ®S.®R, 1, 2 };
    2591         enum ®S.®C c;
    2592         union ®S.T.®U u;
     2643        s.t.c = @S.@R;  // type qualification
     2644        struct @S.@T t = { @S.@R, 1, 2 };
     2645        enum @S.@C c;
     2646        union @S.T.@U u;
    25932647}
    25942648\end{cfa}
     
    26132667const unsigned int size = 5;
    26142668int ia[size];
    2615 ... §\C{// assign values to array ia}§
    2616 qsort( ia, size ); §\C{// sort ascending order using builtin ?<?}§
     2669... $\C{// assign values to array ia}$
     2670qsort( ia, size ); $\C{// sort ascending order using builtin ?<?}$
    26172671{
    2618         ®int ?<?( int x, int y ) { return x > y; }® §\C{// nested routine}§
    2619         qsort( ia, size ); §\C{// sort descending order by local redefinition}§
     2672        @int ?<?( int x, int y ) { return x > y; }@ $\C{// nested routine}$
     2673        qsort( ia, size ); $\C{// sort descending order by local redefinition}$
    26202674}
    26212675\end{cfa}
     
    26252679The following program in undefined in \CFA (and Indexc{gcc})
    26262680\begin{cfa}
    2627 [* [int]( int )] foo() { §\C{// int (* foo())( int )}§
    2628         int ®i® = 7;
     2681[* [int]( int )] foo() { $\C{// int (* foo())( int )}$
     2682        int @i@ = 7;
    26292683        int bar( int p ) {
    2630                 ®i® += 1; §\C{// dependent on local variable}§
    2631                 sout | ®i®;
     2684                @i@ += 1; $\C{// dependent on local variable}$
     2685                sout | @i@;
    26322686        }
    2633         return bar; §\C{// undefined because of local dependence}§
     2687        return bar; $\C{// undefined because of local dependence}$
    26342688}
    26352689int main() {
    2636         * [int]( int ) fp = foo(); §\C{// int (* fp)( int )}§
     2690        * [int]( int ) fp = foo(); $\C{// int (* fp)( int )}$
    26372691        sout | fp( 3 );
    26382692}
     
    26472701In C and \CFA, lists of elements appear in several contexts, such as the parameter list of a routine call.
    26482702\begin{cfa}
    2649 f( ®2, x, 3 + i® ); §\C{// element list}§
     2703f( @2, x, 3 + i@ ); $\C{// element list}$
    26502704\end{cfa}
    26512705A list of elements is called a \newterm{tuple}, and is different from a \Index{comma expression}.
     
    26562710
    26572711In C and most programming languages, functions return at most one value;
    2658 however, many operations have multiple outcomes, some exceptional (see~\VRef{s:ExceptionHandling}).
     2712however, many operations have multiple outcomes, some exceptional \see{\VRef{s:ExceptionHandling}}.
    26592713To emulate functions with multiple return values, \emph{\Index{aggregation}} and/or \emph{\Index{aliasing}} is used.
    26602714
     
    26622716For example, consider C's \Indexc{div} function, which returns the quotient and remainder for a division of an integer value.
    26632717\begin{cfa}
    2664 typedef struct { int quot, rem; } div_t;        §\C[7cm]{// from include stdlib.h}§
     2718typedef struct { int quot, rem; } div_t;        $\C[7cm]{// from include stdlib.h}$
    26652719div_t div( int num, int den );
    2666 div_t qr = div( 13, 5 ); §\C{// return quotient/remainder aggregate}§
    2667 printf( "%d %d\n", qr.quot, qr.rem ); §\C{// print quotient/remainder}§
     2720div_t qr = div( 13, 5 ); $\C{// return quotient/remainder aggregate}$
     2721printf( "%d %d\n", qr.quot, qr.rem ); $\C{// print quotient/remainder}$
    26682722\end{cfa}
    26692723This approach requires a name for the return type and fields, where \Index{naming} is a common programming-language issue.
     
    26752729For example, consider C's \Indexc{modf} function, which returns the integral and fractional part of a floating value.
    26762730\begin{cfa}
    2677 double modf( double x, double * i ); §\C{// from include math.h}§
    2678 double intp, frac = modf( 13.5, &intp ); §\C{// return integral and fractional components}§
    2679 printf( "%g %g\n", intp, frac ); §\C{// print integral/fractional components}§
     2731double modf( double x, double * i ); $\C{// from include math.h}$
     2732double intp, frac = modf( 13.5, &intp ); $\C{// return integral and fractional components}$
     2733printf( "%g %g\n", intp, frac ); $\C{// print integral/fractional components}$
    26802734\end{cfa}
    26812735This approach requires allocating storage for the return values, which complicates the call site with a sequence of variable declarations leading to the call.
     
    27042758When a function call is passed as an argument to another call, the best match of actual arguments to formal parameters is evaluated given all possible expression interpretations in the current scope.
    27052759\begin{cfa}
    2706 void g( int, int ); §\C{// 1}§
    2707 void g( double, double ); §\C{// 2}§
    2708 g( div( 13, 5 ) ); §\C{// select 1}§
    2709 g( modf( 13.5 ) ); §\C{// select 2}§
     2760void g( int, int ); $\C{// 1}$
     2761void g( double, double ); $\C{// 2}$
     2762g( div( 13, 5 ) ); $\C{// select 1}$
     2763g( modf( 13.5 ) ); $\C{// select 2}$
    27102764\end{cfa}
    27112765In this case, there are two overloaded ©g© routines.
     
    27162770The previous examples can be rewritten passing the multiple returned-values directly to the ©printf© function call.
    27172771\begin{cfa}
    2718 [ int, int ] div( int x, int y ); §\C{// from include stdlib}§
    2719 printf( "%d %d\n", div( 13, 5 ) ); §\C{// print quotient/remainder}§
    2720 
    2721 [ double, double ] modf( double x ); §\C{// from include math}§
    2722 printf( "%g %g\n", modf( 13.5 ) ); §\C{// print integral/fractional components}§
     2772[ int, int ] div( int x, int y ); $\C{// from include stdlib}$
     2773printf( "%d %d\n", div( 13, 5 ) ); $\C{// print quotient/remainder}$
     2774
     2775[ double, double ] modf( double x ); $\C{// from include math}$
     2776printf( "%g %g\n", modf( 13.5 ) ); $\C{// print integral/fractional components}$
    27232777\end{cfa}
    27242778This approach provides the benefits of compile-time checking for appropriate return statements as in aggregation, but without the required verbosity of declaring a new named type.
     
    27302784\begin{cfa}
    27312785int quot, rem;
    2732 [ quot, rem ] = div( 13, 5 ); §\C{// assign multiple variables}§
    2733 printf( "%d %d\n", quot, rem ); §\C{// print quotient/remainder}\CRT§
     2786[ quot, rem ] = div( 13, 5 ); $\C{// assign multiple variables}$
     2787printf( "%d %d\n", quot, rem ); $\C{// print quotient/remainder}\CRT$
    27342788\end{cfa}
    27352789Here, the multiple return-values are matched in much the same way as passing multiple return-values to multiple parameters in a call.
     
    27602814In \CFA, it is possible to overcome this restriction by declaring a \newterm{tuple variable}.
    27612815\begin{cfa}
    2762 [int, int] ®qr® = div( 13, 5 ); §\C{// initialize tuple variable}§
    2763 printf( "%d %d\n", ®qr® ); §\C{// print quotient/remainder}§
     2816[int, int] @qr@ = div( 13, 5 ); $\C{// initialize tuple variable}$
     2817printf( "%d %d\n", @qr@ ); $\C{// print quotient/remainder}$
    27642818\end{cfa}
    27652819It is now possible to match the multiple return-values to a single variable, in much the same way as \Index{aggregation}.
     
    27672821One way to access the individual components of a tuple variable is with assignment.
    27682822\begin{cfa}
    2769 [ quot, rem ] = qr; §\C{// assign multiple variables}§
     2823[ quot, rem ] = qr; $\C{// assign multiple variables}$
    27702824\end{cfa}
    27712825
     
    27902844[int, double] * p;
    27912845
    2792 int y = x.0; §\C{// access int component of x}§
    2793 y = f().1; §\C{// access int component of f}§
    2794 p->0 = 5; §\C{// access int component of tuple pointed-to by p}§
    2795 g( x.1, x.0 ); §\C{// rearrange x to pass to g}§
    2796 double z = [ x, f() ].0.1; §\C{// access second component of first component of tuple expression}§
     2846int y = x.0; $\C{// access int component of x}$
     2847y = f().1; $\C{// access int component of f}$
     2848p->0 = 5; $\C{// access int component of tuple pointed-to by p}$
     2849g( x.1, x.0 ); $\C{// rearrange x to pass to g}$
     2850double z = [ x, f() ].0.1; $\C{// access second component of first component of tuple expression}$
    27972851\end{cfa}
    27982852Tuple-index expressions can occur on any tuple-typed expression, including tuple-returning functions, square-bracketed tuple expressions, and other tuple-index expressions, provided the retrieved component is also a tuple.
     
    28012855
    28022856\subsection{Flattening and Structuring}
     2857\label{s:FlatteningStructuring}
    28032858
    28042859As evident in previous examples, tuples in \CFA do not have a rigid structure.
     
    28612916double y;
    28622917[int, double] z;
    2863 [y, x] = 3.14; §\C{// mass assignment}§
    2864 [x, y] = z;                                                         §\C{// multiple assignment}§
    2865 z = 10;                                                         §\C{// mass assignment}§
    2866 z = [x, y]; §\C{// multiple assignment}§
     2918[y, x] = 3.14; $\C{// mass assignment}$
     2919[x, y] = z;                                                         $\C{// multiple assignment}$
     2920z = 10;                                                         $\C{// mass assignment}$
     2921z = [x, y]; $\C{// multiple assignment}$
    28672922\end{cfa}
    28682923Let $L_i$ for $i$ in $[0, n)$ represent each component of the flattened left side, $R_i$ represent each component of the flattened right side of a multiple assignment, and $R$ represent the right side of a mass assignment.
     
    28722927\begin{cfa}
    28732928[ int, int ] x, y, z;
    2874 [ x, y ] = z;                                              §\C{// multiple assignment, invalid 4 != 2}§
     2929[ x, y ] = z;                                              $\C{// multiple assignment, invalid 4 != 2}$
    28752930\end{cfa}
    28762931Multiple assignment assigns $R_i$ to $L_i$ for each $i$.
     
    29082963        double c, d;
    29092964        [ void ] f( [ int, int ] );
    2910         f( [ c, a ] = [ b, d ] = 1.5 ); §\C{// assignments in parameter list}§
     2965        f( [ c, a ] = [ b, d ] = 1.5 ); $\C{// assignments in parameter list}$
    29112966\end{cfa}
    29122967The tuple expression begins with a mass assignment of ©1.5© into ©[b, d]©, which assigns ©1.5© into ©b©, which is truncated to ©1©, and ©1.5© into ©d©, producing the tuple ©[1, 1.5]© as a result.
     
    29212976\begin{cfa}
    29222977struct S;
    2923 void ?{}(S *); §\C{// (1)}§
    2924 void ?{}(S *, int); §\C{// (2)}§
    2925 void ?{}(S * double); §\C{// (3)}§
    2926 void ?{}(S *, S); §\C{// (4)}§
    2927 
    2928 [S, S] x = [3, 6.28]; §\C{// uses (2), (3), specialized constructors}§
    2929 [S, S] y; §\C{// uses (1), (1), default constructor}§
    2930 [S, S] z = x.0; §\C{// uses (4), (4), copy constructor}§
     2978void ?{}(S *); $\C{// (1)}$
     2979void ?{}(S *, int); $\C{// (2)}$
     2980void ?{}(S * double); $\C{// (3)}$
     2981void ?{}(S *, S); $\C{// (4)}$
     2982
     2983[S, S] x = [3, 6.28]; $\C{// uses (2), (3), specialized constructors}$
     2984[S, S] y; $\C{// uses (1), (1), default constructor}$
     2985[S, S] z = x.0; $\C{// uses (4), (4), copy constructor}$
    29312986\end{cfa}
    29322987In this example, ©x© is initialized by the multiple constructor calls ©?{}(&x.0, 3)© and ©?{}(&x.1, 6.28)©, while ©y© is initialized by two default constructor calls ©?{}(&y.0)© and ©?{}(&y.1)©.
     
    29693024A member-access tuple may be used anywhere a tuple can be used, \eg:
    29703025\begin{cfa}
    2971 s.[ y, z, x ] = [ 3, 3.2, 'x' ]; §\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}§
    2972 f( s.[ y, z ] ); §\C{// equivalent to f( s.y, s.z )}§
     3026s.[ y, z, x ] = [ 3, 3.2, 'x' ]; $\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}$
     3027f( s.[ y, z ] ); $\C{// equivalent to f( s.y, s.z )}$
    29733028\end{cfa}
    29743029Note, the fields appearing in a record-field tuple may be specified in any order;
     
    29803035void f( double, long );
    29813036
    2982 f( x.[ 0, 3 ] ); §\C{// f( x.0, x.3 )}§
    2983 x.[ 0, 1 ] = x.[ 1, 0 ]; §\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}§
     3037f( x.[ 0, 3 ] ); $\C{// f( x.0, x.3 )}$
     3038x.[ 0, 1 ] = x.[ 1, 0 ]; $\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}$
    29843039[ long, int, long ] y = x.[ 2, 0, 2 ];
    29853040\end{cfa}
     
    29983053\begin{cfa}
    29993054[ int, float, double ] f();
    3000 [ double, float ] x = f().[ 2, 1 ]; §\C{// f() called once}§
     3055[ double, float ] x = f().[ 2, 1 ]; $\C{// f() called once}$
    30013056\end{cfa}
    30023057
     
    30113066That is, a cast can be used to select the type of an expression when it is ambiguous, as in the call to an overloaded function.
    30123067\begin{cfa}
    3013 int f(); §\C{// (1)}§
    3014 double f(); §\C{// (2)}§
    3015 
    3016 f(); §\C{// ambiguous - (1),(2) both equally viable}§
    3017 (int)f(); §\C{// choose (2)}§
     3068int f(); $\C{// (1)}$
     3069double f(); $\C{// (2)}$
     3070
     3071f(); $\C{// ambiguous - (1),(2) both equally viable}$
     3072(int)f(); $\C{// choose (2)}$
    30183073\end{cfa}
    30193074Since casting is a fundamental operation in \CFA, casts need to be given a meaningful interpretation in the context of tuples.
     
    30233078void g();
    30243079
    3025 (void)f(); §\C{// valid, ignore results}§
    3026 (int)g(); §\C{// invalid, void cannot be converted to int}§
     3080(void)f(); $\C{// valid, ignore results}$
     3081(int)g(); $\C{// invalid, void cannot be converted to int}$
    30273082
    30283083struct A { int x; };
    3029 (struct A)f(); §\C{// invalid, int cannot be converted to A}§
     3084(struct A)f(); $\C{// invalid, int cannot be converted to A}$
    30303085\end{cfa}
    30313086In C, line 4 is a valid cast, which calls ©f© and discards its result.
     
    30433098        [int, [int, int], int] g();
    30443099
    3045         ([int, double])f(); §\C{// (1) valid}§
    3046         ([int, int, int])g(); §\C{// (2) valid}§
    3047         ([void, [int, int]])g(); §\C{// (3) valid}§
    3048         ([int, int, int, int])g(); §\C{// (4) invalid}§
    3049         ([int, [int, int, int]])g(); §\C{// (5) invalid}§
     3100        ([int, double])f(); $\C{// (1) valid}$
     3101        ([int, int, int])g(); $\C{// (2) valid}$
     3102        ([void, [int, int]])g(); $\C{// (3) valid}$
     3103        ([int, int, int, int])g(); $\C{// (4) invalid}$
     3104        ([int, [int, int, int]])g(); $\C{// (5) invalid}$
    30503105\end{cfa}
    30513106
     
    31073162void f([int, int], int, int);
    31083163
    3109 f([0, 0], 0, 0); §\C{// no cost}§
    3110 f(0, 0, 0, 0); §\C{// cost for structuring}§
    3111 f([0, 0,], [0, 0]); §\C{// cost for flattening}§
    3112 f([0, 0, 0], 0); §\C{// cost for flattening and structuring}§
     3164f([0, 0], 0, 0); $\C{// no cost}$
     3165f(0, 0, 0, 0); $\C{// cost for structuring}$
     3166f([0, 0,], [0, 0]); $\C{// cost for flattening}$
     3167f([0, 0, 0], 0); $\C{// cost for flattening and structuring}$
    31133168\end{cfa}
    31143169
     
    31463201The general syntax of a lexical list is:
    31473202\begin{cfa}
    3148 [ §\emph{exprlist}§ ]
     3203[ $\emph{exprlist}$ ]
    31493204\end{cfa}
    31503205where ©$\emph{exprlist}$© is a list of one or more expressions separated by commas.
     
    31583213Tuples are permitted to contain sub-tuples (\ie nesting), such as ©[ [ 14, 21 ], 9 ]©, which is a 2-element tuple whose first element is itself a tuple.
    31593214Note, a tuple is not a record (structure);
    3160 a record denotes a single value with substructure, whereas a tuple is multiple values with no substructure (see flattening coercion in Section 12.1).
     3215a record denotes a single value with substructure, whereas a tuple is multiple values with no substructure \see{flattening coercion in \VRef{s:FlatteningStructuring}}.
    31613216In essence, tuples are largely a compile time phenomenon, having little or no runtime presence.
    31623217
     
    31663221The general syntax of a tuple type is:
    31673222\begin{cfa}
    3168 [ §\emph{typelist}§ ]
     3223[ $\emph{typelist}$ ]
    31693224\end{cfa}
    31703225where ©$\emph{typelist}$© is a list of one or more legal \CFA or C type specifications separated by commas, which may include other tuple type specifications.
     
    31733228[ unsigned int, char ]
    31743229[ double, double, double ]
    3175 [ * int, int * ] §\C{// mix of CFA and ANSI}§
     3230[ * int, int * ] $\C{// mix of CFA and ANSI}$
    31763231[ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    31773232\end{cfa}
     
    31803235Examples of declarations using tuple types are:
    31813236\begin{cfa}
    3182 [ int, int ] x; §\C{// 2 element tuple, each element of type int}§
    3183 * [ char, char ] y; §\C{// pointer to a 2 element tuple}§
     3237[ int, int ] x; $\C{// 2 element tuple, each element of type int}$
     3238* [ char, char ] y; $\C{// pointer to a 2 element tuple}$
    31843239[ [ int, int ] ] z ([ int, int ]);
    31853240\end{cfa}
     
    31983253[ int, int ] w1;
    31993254[ int, int, int ] w2;
    3200 [ void ] f (int, int, int); §\C{// three input parameters of type int}§
    3201 [ void ] g ([ int, int, int ]); §\C{3 element tuple as input}§
     3255[ void ] f (int, int, int); $\C{// three input parameters of type int}$
     3256[ void ] g ([ int, int, int ]); $\C{3 element tuple as input}$
    32023257f( [ 1, 2, 3 ] );
    32033258f( w1, 3 );
     
    32793334[ int, int, int, int ] w = [ 1, 2, 3, 4 ];
    32803335int x = 5;
    3281 [ x, w ] = [ w, x ]; §\C{// all four tuple coercions}§
     3336[ x, w ] = [ w, x ]; $\C{// all four tuple coercions}$
    32823337\end{cfa}
    32833338Starting on the right-hand tuple in the last assignment statement, w is opened, producing a tuple of four values;
     
    32853340This tuple is then flattened, yielding ©[ 1, 2, 3, 4, 5 ]©, which is structured into ©[ 1, [ 2, 3, 4, 5 ] ]© to match the tuple type of the left-hand side.
    32863341The tuple ©[ 2, 3, 4, 5 ]© is then closed to create a tuple value.
    3287 Finally, ©x© is assigned ©1© and ©w© is assigned the tuple value using multiple assignment (see Section 14).
     3342Finally, ©x© is assigned ©1© and ©w© is assigned the tuple value using \Index{multiple assignment} \see{\VRef{s:TupleAssignment}}.
    32883343\begin{rationale}
    32893344A possible additional language extension is to use the structuring coercion for tuples to initialize a complex record with a tuple.
     
    32963351Mass assignment has the following form:
    32973352\begin{cfa}
    3298 [ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = §\emph{expr}§;
     3353[ $\emph{lvalue}$, ... , $\emph{lvalue}$ ] = $\emph{expr}$;
    32993354\end{cfa}
    33003355\index{lvalue}
     
    33363391Multiple assignment has the following form:
    33373392\begin{cfa}
    3338 [ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = [ §\emph{expr}§, ... , §\emph{expr}§ ];
     3393[ $\emph{lvalue}$, ... , $\emph{lvalue}$ ] = [ $\emph{expr}$, ... , $\emph{expr}$ ];
    33393394\end{cfa}
    33403395\index{lvalue}
     
    33673422both these examples produce indeterminate results:
    33683423\begin{cfa}
    3369 f( x++, x++ ); §\C{// C routine call with side effects in arguments}§
    3370 [ v1, v2 ] = [ x++, x++ ]; §\C{// side effects in righthand side of multiple assignment}§
     3424f( x++, x++ ); $\C{// C routine call with side effects in arguments}$
     3425[ v1, v2 ] = [ x++, x++ ]; $\C{// side effects in right-hand side of multiple assignment}$
    33713426\end{cfa}
    33723427
     
    33773432Cascade assignment has the following form:
    33783433\begin{cfa}
    3379 §\emph{tuple}§ = §\emph{tuple}§ = ... = §\emph{tuple}§;
     3434$\emph{tuple}$ = $\emph{tuple}$ = ... = $\emph{tuple}$;
    33803435\end{cfa}
    33813436and it has the same parallel semantics as for mass and multiple assignment.
     
    34243479\begin{cfa}
    34253480int x = 1, y = 2, z = 3;
    3426 sout | x ®|® y ®|® z;
     3481sout | x @|@ y @|@ z;
    34273482\end{cfa}
    34283483&
    34293484\begin{cfa}
    34303485
    3431 cout << x ®<< " "® << y ®<< " "® << z << endl;
     3486cout << x @<< " "@ << y @<< " "@ << z << endl;
    34323487\end{cfa}
    34333488&
     
    34383493\\
    34393494\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3440 1® ®2® ®3
     34951@ @2@ @3
    34413496\end{cfa}
    34423497&
    34433498\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3444 1® ®2® ®3
     34991@ @2@ @3
    34453500\end{cfa}
    34463501&
    34473502\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3448 1® ®2® ®3
     35031@ @2@ @3
    34493504\end{cfa}
    34503505\end{tabular}
     
    34543509\begin{cfa}
    34553510[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    3456 sout | t1 | t2; §\C{// print tuples}§
     3511sout | t1 | t2; $\C{// print tuples}$
    34573512\end{cfa}
    34583513\begin{cfa}[showspaces=true,aboveskip=0pt]
    3459 1®, ®2®, ®3 4®, ®5®, ®6
     35141@, @2@, @3 4@, @5@, @6
    34603515\end{cfa}
    34613516Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority \emph{overloadable} operator, other than assignment.
     
    34663521&
    34673522\begin{cfa}
    3468 sout | x * 3 | y + 1 | z << 2 | x == y | ®(®x | y®)® | ®(®x || y®)® | ®(®x > z ? 1 : 2®)®;
     3523sout | x * 3 | y + 1 | z << 2 | x == y | @(@x | y@)@ | @(@x || y@)@ | @(@x > z ? 1 : 2@)@;
    34693524\end{cfa}
    34703525\\
     
    34723527&
    34733528\begin{cfa}
    3474 cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << ®(®x | y®)® << ®(®x || y®)® << ®(®x > z ? 1 : 2®)® << endl;
     3529cout << x * 3 << y + 1 << @(@z << 2@)@ << @(@x == y@)@ << @(@x | y@)@ << @(@x || y@)@ << @(@x > z ? 1 : 2@)@ << endl;
    34753530\end{cfa}
    34763531\\
     
    35073562\\
    35083563\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3509 ®1® ®2.5® ®A®
     3564@1@ @2.5@ @A@
    35103565
    35113566
     
    35133568&
    35143569\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3515 ®1® ®2.5® ®A®
     3570@1@ @2.5@ @A@
    35163571
    35173572
     
    35193574&
    35203575\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3521 ®1®
    3522 ®2.5®
    3523 ®A®
     3576@1@
     3577@2.5@
     3578@A@
    35243579\end{cfa}
    35253580\end{tabular}
     
    35573612
    35583613\item
    3559 {\lstset{language=CFA,deletedelim=**[is][]{¢}{¢}}
    3560 A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[basicstyle=\tt]@,.;!?)]}%¢»@, where \lstinline[basicstyle=\tt]@»@ is a closing citation mark.
    3561 \begin{cfa}[belowskip=0pt]
     3614A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \LstStringStyle{,.;!?)]\}\%\textcent\guillemotright}, where \LstStringStyle{\guillemotright} a closing citation mark.
     3615\begin{cfa}
    35623616sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    3563                 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
    3564 \end{cfa}
    3565 \begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
    3566 1®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7§\color{red}\textcent§ x 8®»® x 9®)® x 10®]® x 11®}® x
    3567 \end{cfa}}%
    3568 
    3569 \item
    3570 A separator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$£¥¡¿«@, where \lstinline[basicstyle=\tt]@¡¿@ are inverted opening exclamation and question marks, and \lstinline[basicstyle=\tt]@«@ is an opening citation mark.
     3617           | 7 | "$\LstStringStyle{\textcent}$ x" | 8 | "$\LstStringStyle{\guillemotright}$ x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
     3618\end{cfa}
     3619\begin{cfa}[showspaces=true]
     36201@,@ x 2@.@ x 3@;@ x 4@!@ x 5@?@ x 6@%@ x 7$\R{\LstStringStyle{\textcent}}$ x 8$\R{\LstStringStyle{\guillemotright}}$ x 9@)@ x 10@]@ x 11@}@ x
     3621\end{cfa}
     3622
     3623\item
     3624A separator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \LstStringStyle{([\{=\$\textsterling\textyen\textexclamdown\textquestiondown\guillemotleft}, where \LstStringStyle{\textexclamdown\textquestiondown} are inverted opening exclamation and question marks, and \LstStringStyle{\guillemotleft} is an opening citation mark.
    35713625%$
    3572 \begin{cfa}[mathescape=off]
    3573 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
    3574                 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
     3626\begin{cfa}
     3627sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x $\LstStringStyle{\textsterling}$" | 6 | "x $\LstStringStyle{\textyen}$"
     3628           | 7 | "x $\LstStringStyle{\textexclamdown}$" | 8 | "x $\LstStringStyle{\textquestiondown}$" | 9 | "x $\LstStringStyle{\guillemotleft}$" | 10;
    35753629\end{cfa}
    35763630%$
    3577 \begin{cfa}[mathescape=off,basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
    3578 x ®(®1 x ®[®2 x ®{®3 x ®=®4 x ®$®5 x ®£®6 x ®¥®7 x ®¡®8 x ®¿®9 x ®«®10
     3631\begin{cfa}[showspaces=true]
     3632x @(@1 x @[@2 x @{@3 x @=@4 x $\LstStringStyle{\textdollar}$5 x $\R{\LstStringStyle{\textsterling}}$6 x $\R{\LstStringStyle{\textyen}}$7 x $\R{\LstStringStyle{\textexclamdown}}$8 x $\R{\LstStringStyle{\textquestiondown}}$9 x $\R{\LstStringStyle{\guillemotleft}}$10
    35793633\end{cfa}
    35803634%$
    35813635
    35823636\item
    3583 A seperator does not appear before/after a C string starting/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]@`'": \t\v\f\r\n@
    3584 \begin{cfa}[belowskip=0pt]
     3637A seperator does not appear before/after a C string starting/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]{`'": \t\v\f\r\n}
     3638\begin{cfa}
    35853639sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx";
    35863640\end{cfa}
    3587 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
    3588 x®`®1®`®x§\color{red}\texttt{'}§2§\color{red}\texttt{'}§x§\color{red}\texttt{"}§3§\color{red}\texttt{"}§x®:®4®:®x® ®5® ®x®      ®6®     ®x
     3641\begin{cfa}[showspaces=true,showtabs=true]
     3642x@`@1@`@x$\R{\texttt{'}}$2$\R{\texttt{'}}$x$\R{\texttt{"}}$3$\R{\texttt{"}}$x@:@4@:@x@ @5@ @x@  @6@     @x
    35893643\end{cfa}
    35903644
    35913645\item
    35923646If a space is desired before or after one of the special string start/end characters, simply insert a space.
    3593 \begin{cfa}[belowskip=0pt]
    3594 sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4;
    3595 \end{cfa}
    3596 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
    3597 x (® ®1® ®) x 2® ®, x 3® ®:x:® ®4
     3647\begin{cfa}
     3648sout | "x ($\R{\texttt{\textvisiblespace}}$" | 1 | "$\R{\texttt{\textvisiblespace}}$) x" | 2 | "$\R{\texttt{\textvisiblespace}}$, x" | 3 | "$\R{\texttt{\textvisiblespace}}$:x:$\R{\texttt{\textvisiblespace}}$" | 4;
     3649\end{cfa}
     3650\begin{cfa}[showspaces=true,showtabs=true]
     3651x (@ @1@ @) x 2@ @, x 3@ @:x:@ @4
    35983652\end{cfa}
    35993653\end{enumerate}
     
    36083662\Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sep}\index{manipulator!sep@©sep©}/\Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string.
    36093663The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    3610 \begin{cfa}[mathescape=off,belowskip=0pt]
    3611 sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§
    3612 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"";
     3664\begin{cfa}[escapechar=off,belowskip=0pt]
     3665sepSet( sout, ", $" ); $\C{// set separator from " " to ", \$"}$
     3666sout | 1 | 2 | 3 | " \"" | @sep@ | "\"";
    36133667\end{cfa}
    36143668%$
    36153669\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    3616 1®, $®2®, $®3 ®", $"®
     36701@, $@2@, $@3 @", $"@
    36173671\end{cfa}
    36183672%$
    36193673\begin{cfa}[belowskip=0pt]
    3620 sepSet( sout, " " ); §\C{// reset separator to " "}§
    3621 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"";
     3674sepSet( sout, " " ); $\C{// reset separator to " "}$
     3675sout | 1 | 2 | 3 | " \"" | @sepGet( sout )@ | "\"";
    36223676\end{cfa}
    36233677\begin{cfa}[showspaces=true,aboveskip=0pt]
    3624 1® ®2® ®3 ®" "®
     36781@ @2@ @3 @" "@
    36253679\end{cfa}
    36263680©sepGet© can be used to store a separator and then restore it:
    36273681\begin{cfa}[belowskip=0pt]
    3628 char store[®sepSize®]; §\C{// sepSize is the maximum separator size}§
    3629 strcpy( store, sepGet( sout ) ); §\C{// copy current separator}§
    3630 sepSet( sout, "_" ); §\C{// change separator to underscore}§
     3682char store[@sepSize@]; $\C{// sepSize is the maximum separator size}$
     3683strcpy( store, sepGet( sout ) ); $\C{// copy current separator}$
     3684sepSet( sout, "_" ); $\C{// change separator to underscore}$
    36313685sout | 1 | 2 | 3;
    36323686\end{cfa}
    36333687\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3634 1®_®2®_®3
     36881@_@2@_@3
    36353689\end{cfa}
    36363690\begin{cfa}[belowskip=0pt]
    3637 sepSet( sout, store ); §\C{// change separator back to original}§
     3691sepSet( sout, store ); $\C{// change separator back to original}$
    36383692sout | 1 | 2 | 3;
    36393693\end{cfa}
    36403694\begin{cfa}[showspaces=true,aboveskip=0pt]
    3641 1® ®2® ®3
     36951@ @2@ @3
    36423696\end{cfa}
    36433697
     
    36463700The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    36473701\begin{cfa}[belowskip=0pt]
    3648 sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§
    3649 sout | t1 | t2 | " \"" | ®sepTuple® | "\"";
     3702sepSetTuple( sout, " " ); $\C{// set tuple separator from ", " to " "}$
     3703sout | t1 | t2 | " \"" | @sepTuple@ | "\"";
    36503704\end{cfa}
    36513705\begin{cfa}[showspaces=true,aboveskip=0pt]
    3652 1 2 3 4 5 6 ®" "®
     37061 2 3 4 5 6 @" "@
    36533707\end{cfa}
    36543708\begin{cfa}[belowskip=0pt]
    3655 sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§
    3656 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"";
     3709sepSetTuple( sout, ", " ); $\C{// reset tuple separator to ", "}$
     3710sout | t1 | t2 | " \"" | @sepGetTuple( sout )@ | "\"";
    36573711\end{cfa}
    36583712\begin{cfa}[showspaces=true,aboveskip=0pt]
    3659 1, 2, 3 4, 5, 6 ®", "®
     37131, 2, 3 4, 5, 6 @", "@
    36603714\end{cfa}
    36613715As for ©sepGet©, ©sepGetTuple© can be use to store a tuple separator and then restore it.
     
    36643718\Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} toggle printing the separator.
    36653719\begin{cfa}[belowskip=0pt]
    3666 sout | sepDisable | 1 | 2 | 3; §\C{// turn off implicit separator}§
     3720sout | sepDisable | 1 | 2 | 3; $\C{// turn off implicit separator}$
    36673721\end{cfa}
    36683722\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36703724\end{cfa}
    36713725\begin{cfa}[belowskip=0pt]
    3672 sout | sepEnable | 1 | 2 | 3; §\C{// turn on implicit separator}§
     3726sout | sepEnable | 1 | 2 | 3; $\C{// turn on implicit separator}$
    36733727\end{cfa}
    36743728\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36793733\Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} toggle printing the separator with respect to the next printed item, and then return to the global seperator setting.
    36803734\begin{cfa}[belowskip=0pt]
    3681 sout | 1 | sepOff | 2 | 3; §\C{// turn off implicit separator for the next item}§
     3735sout | 1 | sepOff | 2 | 3; $\C{// turn off implicit separator for the next item}$
    36823736\end{cfa}
    36833737\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36853739\end{cfa}
    36863740\begin{cfa}[belowskip=0pt]
    3687 sout | sepDisable | 1 | sepOn | 2 | 3; §\C{// turn on implicit separator for the next item}§
     3741sout | sepDisable | 1 | sepOn | 2 | 3; $\C{// turn on implicit separator for the next item}$
    36883742\end{cfa}
    36893743\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36923746The tuple separator also responses to being turned on and off.
    36933747\begin{cfa}[belowskip=0pt]
    3694 sout | t1 | sepOff | t2; §\C{// turn off implicit separator for the next item}§
     3748sout | t1 | sepOff | t2; $\C{// turn off implicit separator for the next item}$
    36953749\end{cfa}
    36963750\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    37003754use ©sep© to accomplish this functionality.
    37013755\begin{cfa}[belowskip=0pt]
    3702 sout | sepOn | 1 | 2 | 3 | sepOn; §\C{// sepOn does nothing at start/end of line}§
     3756sout | sepOn | 1 | 2 | 3 | sepOn; $\C{// sepOn does nothing at start/end of line}$
    37033757\end{cfa}
    37043758\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    37063760\end{cfa}
    37073761\begin{cfa}[belowskip=0pt]
    3708 sout | sep | 1 | 2 | 3 | sep ; §\C{// use sep to print separator at start/end of line}§
     3762sout | sep | 1 | 2 | 3 | sep ; $\C{// use sep to print separator at start/end of line}$
    37093763\end{cfa}
    37103764\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3711 ® ®1 2 3® ®
     3765@ @1 2 3@ @
    37123766\end{cfa}
    37133767\end{enumerate}
     
    37213775\begin{enumerate}[parsep=0pt]
    37223776\item
    3723 \Indexc{nl}\index{manipulator!nl@©nl©} scans characters until the next newline character, i.e., ignore the remaining characters in the line.
     3777\Indexc{nl}\index{manipulator!nl@©nl©} scans characters until the next newline character, \ie ignore the remaining characters in the line.
    37243778\item
    37253779\Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} reads the newline character, when reading single characters.
     
    37293783For example, in:
    37303784\begin{cfa}
    3731 sin | i | ®nl® | j;
    3732 1 ®2®
     3785sin | i | @nl@ | j;
     37861 @2@
    373337873
    37343788\end{cfa}
     
    37403794\Indexc{nl}\index{manipulator!nl@©nl©} inserts a newline.
    37413795\begin{cfa}
    3742 sout | nl; §\C{// only print newline}§
    3743 sout | 2; §\C{// implicit newline}§
    3744 sout | 3 | nl | 4 | nl; §\C{// terminating nl merged with implicit newline}§
    3745 sout | 5 | nl | nl; §\C{// again terminating nl merged with implicit newline}§
    3746 sout | 6; §\C{// implicit newline}§
     3796sout | nl; $\C{// only print newline}$
     3797sout | 2; $\C{// implicit newline}$
     3798sout | 3 | nl | 4 | nl; $\C{// terminating nl merged with implicit newline}$
     3799sout | 5 | nl | nl; $\C{// again terminating nl merged with implicit newline}$
     3800sout | 6; $\C{// implicit newline}$
    37473801
    374838022
     
    377138250b0 0b11011 0b11011 0b11011 0b11011
    37723826sout | bin( -27HH ) | bin( -27H ) | bin( -27 ) | bin( -27L );
    3773 0b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b®(58 1s)®100101
     38270b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b@(58 1s)@100101
    37743828\end{cfa}
    37753829
     
    38103864\begin{cfa}[belowskip=0pt]
    38113865sout | upcase( bin( 27 ) ) | upcase( hex( 27 ) ) | upcase( 27.5e-10 ) | upcase( hex( 27.5 ) );
    3812 0®B®11011 0®X®1®B® 2.75®E®-09 0®X®1.®B®8®P®+4
     38660@B@11011 0@X@1@B@ 2.75@E@-09 0@X@1.@B@8@P@+4
    38133867\end{cfa}
    38143868
     
    38263880\begin{cfa}[belowskip=0pt]
    38273881sout | 0. | nodp( 0. ) | 27.0 | nodp( 27.0 ) | nodp( 27.5 );
    3828 0.0 ®0® 27.0 ®27® 27.5
     38820.0 @0@ 27.0 @27@ 27.5
    38293883\end{cfa}
    38303884
     
    38333887\begin{cfa}[belowskip=0pt]
    38343888sout | sign( 27 ) | sign( -27 ) | sign( 27. ) | sign( -27. ) | sign( 27.5 ) | sign( -27.5 );
    3835 ®+®27 -27 ®+®27.0 -27.0 ®+®27.5 -27.5
     3889@+@27 -27 @+@27.0 -27.0 @+@27.5 -27.5
    38363890\end{cfa}
    38373891
     
    38463900\end{cfa}
    38473901\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3848 ®  ®34 ® ®34 34
    3849 ®  ®4.000000 ® ®4.000000 4.000000
    3850 ®  ®ab ® ®ab ab
     3902@  @34 @ @34 34
     3903@  @4.000000 @ @4.000000 4.000000
     3904@  @ab @ @ab ab
    38513905\end{cfa}
    38523906If the value is larger, it is printed without truncation, ignoring the ©minimum©.
     
    38573911\end{cfa}
    38583912\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3859 3456®7® 345®67® 34®567®
    3860 3456®.® 345®6.® 34®56.®
    3861 abcd®e® abc®de® ab®cde®
     39133456@7@ 345@67@ 34@567@
     39143456@.@ 345@6.@ 34@56.@
     3915abcd@e@ abc@de@ ab@cde@
    38623916\end{cfa}
    38633917
     
    38683922\end{cfa}
    38693923\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3870  ®0®34     ®00®34 ®00000000®34
     3924 @0@34     @00@34 @00000000@34
    38713925\end{cfa}
    38723926If the value is larger, it is printed without truncation, ignoring the ©precision©.
     
    38833937\end{cfa}
    38843938\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3885 ®    ® ®00000000®34
     3939@    @ @00000000@34
    38863940\end{cfa}
    38873941For floating-point types, ©precision© is the minimum number of digits after the decimal point.
     
    38903944\end{cfa}
    38913945\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3892 27.®500®     27.®5®      28. 27.®50000000®
    3893 \end{cfa}
    3894 For the C-string type, ©precision© is the maximum number of printed characters, so the string is truncared if it exceeds the maximum.
     394627.@500@     27.@5@      28. 27.@50000000@
     3947\end{cfa}
     3948For the C-string type, ©precision© is the maximum number of printed characters, so the string is truncated if it exceeds the maximum.
    38953949\begin{cfa}[belowskip=0pt]
    38963950sout | wd( 6,8, "abcd" ) | wd( 6,8, "abcdefghijk" ) | wd( 6,3, "abcd" );
     
    39083962\end{cfa}
    39093963\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3910 234.567 234.5®7®  234.®6®    23®5®
     3964234.567 234.5@7@  234.@6@    23@5@
    39113965\end{cfa}
    39123966If a value's magnitude is greater than ©significant©, the value is printed in scientific notation with the specified number of significant digits.
     
    39153969\end{cfa}
    39163970\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3917 234567. 2.3457®e+05® 2.346®e+05® 2.35®e+05®
     3971234567. 2.3457@e+05@ 2.346@e+05@ 2.35@e+05@
    39183972\end{cfa}
    39193973If ©significant© is greater than ©minimum©, it defines the number of printed characters.
     
    39313985\end{cfa}
    39323986\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3933 27®  ® 27.000000  27.500000  027  27.500®    ®
     398727@  @ 27.000000  27.500000  027  27.500@    @
    39343988\end{cfa}
    39353989
     
    39383992\begin{cfa}[belowskip=0pt]
    39393993sout | pad0( wd( 4, 27 ) ) | pad0( wd( 4,3, 27 ) ) | pad0( wd( 8,3, 27.5 ) );
    3940 ®00®27  ®0®27 ®00®27.500
     3994@00@27  @0@27 @00@27.500
    39413995\end{cfa}
    39423996\end{enumerate}
     
    40344088\end{cfa}
    40354089\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4036 ®abc   ®
    4037 ®abc  ®
    4038 ®xx®
     4090@abc   @
     4091@abc  @
     4092@xx@
    40394093\end{cfa}
    40404094
     
    40474101\end{cfa}
    40484102\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4049 ®abcd1233.456E+2®
     4103@abcd1233.456E+2@
    40504104\end{cfa}
    40514105Note, input ©wdi© cannot be overloaded with output ©wd© because both have the same parameters but return different types.
     
    40604114\end{cfa}
    40614115\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4062 ®  -75.35e-4® 25
     4116@  -75.35e-4@ 25
    40634117\end{cfa}
    40644118
     
    40724126\end{cfa}
    40734127\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4074 ®bca®xyz
     4128@bca@xyz
    40754129\end{cfa}
    40764130
     
    40844138\end{cfa}
    40854139\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4086 ®xyz®bca
     4140@xyz@bca
    40874141\end{cfa}
    40884142\end{enumerate}
     
    41014155
    41024156A type definition is different from a typedef in C because a typedef just creates an alias for a type,  while Do.s type definition creates a distinct type.
    4103 This means that users can define distinct function overloads for the new type (see Overloading for more information).
     4157This means that users can define distinct function overloads for the new type \see{\VRef{s:Overloading} for more information}.
    41044158For example:
    41054159
     
    42074261\CFA supports C initialization of structures, but it also adds constructors for more advanced initialization.
    42084262Additionally, \CFA adds destructors that are called when a variable is deallocated (variable goes out of scope or object is deleted).
    4209 These functions take a reference to the structure as a parameter (see References for more information).
     4263These functions take a reference to the structure as a parameter \see{\VRef{s:PointerReference} for more information}.
    42104264
    42114265\begin{figure}
     
    42584312
    42594313\section{Overloading}
     4314\label{s:Overloading}
    42604315
    42614316Overloading refers to the capability of a programmer to define and use multiple objects in a program with the same name.
     
    44684523For example, given
    44694524\begin{cfa}
    4470 auto j = ®...®
     4525auto j = @...@
    44714526\end{cfa}
    44724527and the need to write a routine to compute using ©j©
    44734528\begin{cfa}
    4474 void rtn( ®...® parm );
     4529void rtn( @...@ parm );
    44754530rtn( j );
    44764531\end{cfa}
     
    47134768
    47144769coroutine Fibonacci {
    4715         int fn; §\C{// used for communication}§
     4770        int fn; $\C{// used for communication}$
    47164771};
    47174772void ?{}( Fibonacci * this ) {
     
    47194774}
    47204775void main( Fibonacci * this ) {
    4721         int fn1, fn2; §\C{// retained between resumes}§
    4722         this->fn = 0; §\C{// case 0}§
     4776        int fn1, fn2; $\C{// retained between resumes}$
     4777        this->fn = 0; $\C{// case 0}$
    47234778        fn1 = this->fn;
    4724         suspend(); §\C{// return to last resume}§
    4725 
    4726         this->fn = 1; §\C{// case 1}§
     4779        suspend(); $\C{// return to last resume}$
     4780
     4781        this->fn = 1; $\C{// case 1}$
    47274782        fn2 = fn1;
    47284783        fn1 = this->fn;
    4729         suspend(); §\C{// return to last resume}§
    4730 
    4731         for ( ;; ) { §\C{// general case}§
     4784        suspend(); $\C{// return to last resume}$
     4785
     4786        for ( ;; ) { $\C{// general case}$
    47324787                this->fn = fn1 + fn2;
    47334788                fn2 = fn1;
    47344789                fn1 = this->fn;
    4735                 suspend(); §\C{// return to last resume}§
     4790                suspend(); $\C{// return to last resume}$
    47364791        } // for
    47374792}
    47384793int next( Fibonacci * this ) {
    4739         resume( this ); §\C{// transfer to last suspend}§
     4794        resume( this ); $\C{// transfer to last suspend}$
    47404795        return this->fn;
    47414796}
     
    49645019When building a \CFA module which needs to be callable from C code, users can use the tools to generate a header file suitable for including in these C files with all of the needed declarations.
    49655020
    4966 In order to interoperate with existing C code, \CFA files can still include header files, the contents of which will be enclosed in a C linkage section to indicate C calling conventions (see Interoperability for more information).
     5021In order to interoperate with existing C code, \CFA files can still include header files, the contents of which will be enclosed in a C linkage section to indicate C calling conventions \see{\VRef{s:Interoperability} for more information}.
    49675022
    49685023
     
    62826337In \CFA, there are ambiguous cases with dereference and operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be interpreted as:
    62836338\begin{cfa}
    6284 *?§\color{red}\textvisiblespace§*? §\C{// dereference operator, dereference operator}§
    6285 *§\color{red}\textvisiblespace§?*? §\C{// dereference, multiplication operator}§
     6339*?$\R{\textvisiblespace}$*? $\C{// dereference operator, dereference operator}$
     6340*$\R{\textvisiblespace}$?*? $\C{// dereference, multiplication operator}$
    62866341\end{cfa}
    62876342By default, the first interpretation is selected, which does not yield a meaningful parse.
     
    62926347The ambiguity occurs when the deference operator has no parameters:
    62936348\begin{cfa}
    6294 *?()§\color{red}\textvisiblespace...§ ;
    6295 *?()§\color{red}\textvisiblespace...§(...) ;
     6349*?()$\R{\textvisiblespace...}$ ;
     6350*?()$\R{\textvisiblespace...}$(...) ;
    62966351\end{cfa}
    62976352requiring arbitrary whitespace look-ahead for the routine-call parameter-list to disambiguate.
     
    63016356The remaining cases are with the increment/decrement operators and conditional expression, \eg:
    63026357\begin{cfa}
    6303 i++?§\color{red}\textvisiblespace...§(...);
    6304 i?++§\color{red}\textvisiblespace...§(...);
     6358i++?$\R{\textvisiblespace...}$(...);
     6359i?++$\R{\textvisiblespace...}$(...);
    63056360\end{cfa}
    63066361requiring arbitrary whitespace look-ahead for the operator parameter-list, even though that interpretation is an incorrect expression (juxtaposed identifiers).
    63076362Therefore, it is necessary to disambiguate these cases with a space:
    63086363\begin{cfa}
    6309 i++§\color{red}\textvisiblespace§? i : 0;
    6310 i?§\color{red}\textvisiblespace§++i : 0;
     6364i++$\R{\textvisiblespace}$? i : 0;
     6365i?$\R{\textvisiblespace}$++i : 0;
    63116366\end{cfa}
    63126367
     
    63216376\begin{description}
    63226377\item[Change:] add new keywords \\
    6323 New keywords are added to \CFA (see~\VRef{s:CFAKeywords}).
     6378New keywords are added to \CFA \see{\VRef{s:CFAKeywords}}.
    63246379\item[Rationale:] keywords added to implement new semantics of \CFA.
    63256380\item[Effect on original feature:] change to semantics of well-defined feature. \\
    63266381Any \Celeven programs using these keywords as identifiers are invalid \CFA programs.
    6327 \item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}).
     6382\item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism \see{\VRef{s:BackquoteIdentifiers}}.
    63286383\item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
    63296384\end{description}
     
    63356390\eg:
    63366391\begin{cfa}
    6337 x; §\C{// int x}§
    6338 *y; §\C{// int *y}§
    6339 f( p1, p2 ); §\C{// int f( int p1, int p2 );}§
    6340 g( p1, p2 ) int p1, p2; §\C{// int g( int p1, int p2 );}§
     6392x; $\C{// int x}$
     6393*y; $\C{// int *y}$
     6394f( p1, p2 ); $\C{// int f( int p1, int p2 );}$
     6395g( p1, p2 ) int p1, p2; $\C{// int g( int p1, int p2 );}$
    63416396\end{cfa}
    63426397\CFA continues to support K\&R routine definitions:
    63436398\begin{cfa}
    6344 f( a, b, c ) §\C{// default int return}§
    6345         int a, b; char c §\C{// K\&R parameter declarations}§
     6399f( a, b, c ) $\C{// default int return}$
     6400        int a, b; char c $\C{// K\&R parameter declarations}$
    63466401{
    63476402        ...
     
    63626417int rtn( int i );
    63636418int rtn( char c );
    6364 rtn( 'x' ); §\C{// programmer expects 2nd rtn to be called}§
     6419rtn( 'x' ); $\C{// programmer expects 2nd rtn to be called}$
    63656420\end{cfa}
    63666421\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
     
    63846439\item[Change:] make string literals ©const©:
    63856440\begin{cfa}
    6386 char * p = "abc"; §\C{// valid in C, deprecated in \CFA}§
    6387 char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
     6441char * p = "abc"; $\C{// valid in C, deprecated in \CFA}$
     6442char * q = expr ? "abc" : "de"; $\C{// valid in C, invalid in \CFA}$
    63886443\end{cfa}
    63896444The type of a string literal is changed from ©[] char© to ©const [] char©.
     
    63926447\begin{cfa}
    63936448char * p = "abc";
    6394 p[0] = 'w'; §\C{// segment fault or change constant literal}§
     6449p[0] = 'w'; $\C{// segment fault or change constant literal}$
    63956450\end{cfa}
    63966451The same problem occurs when passing a string literal to a routine that changes its argument.
     
    64046459\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
    64056460\begin{cfa}
    6406 int i; §\C{// forward definition}§
    6407 int *j = ®&i®; §\C{// forward reference, valid in C, invalid in \CFA}§
    6408 int i = 0; §\C{// definition}§
     6461int i; $\C{// forward definition}$
     6462int *j = @&i@; $\C{// forward reference, valid in C, invalid in \CFA}$
     6463int i = 0; $\C{// definition}$
    64096464\end{cfa}
    64106465is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
     
    64126467\begin{cfa}
    64136468struct X { int i; struct X *next; };
    6414 static struct X a; §\C{// forward definition}§
    6415 static struct X b = { 0, ®&a® };§\C{// forward reference, valid in C, invalid in \CFA}§
    6416 static struct X a = { 1, &b }; §\C{// definition}§
     6469static struct X a; $\C{// forward definition}$
     6470static struct X b = { 0, @&a@ };$\C{// forward reference, valid in C, invalid in \CFA}$
     6471static struct X a = { 1, &b }; $\C{// definition}$
    64176472\end{cfa}
    64186473\item[Rationale:] avoids having different initialization rules for builtin types and user-defined types.
     
    64266481\item[Change:] have ©struct© introduce a scope for nested types:
    64276482\begin{cfa}
    6428 enum ®Colour® { R, G, B, Y, C, M };
     6483enum @Colour@ { R, G, B, Y, C, M };
    64296484struct Person {
    6430         enum ®Colour® { R, G, B };      §\C[7cm]{// nested type}§
    6431         struct Face { §\C{// nested type}§
    6432                 ®Colour® Eyes, Hair; §\C{// type defined outside (1 level)}§
     6485        enum @Colour@ { R, G, B };      $\C[7cm]{// nested type}$
     6486        struct Face { $\C{// nested type}$
     6487                @Colour@ Eyes, Hair; $\C{// type defined outside (1 level)}$
    64336488        };
    6434         ®.Colour® shirt; §\C{// type defined outside (top level)}§
    6435         ®Colour® pants; §\C{// type defined same level}§
    6436         Face looks[10]; §\C{// type defined same level}§
     6489        @.Colour@ shirt; $\C{// type defined outside (top level)}$
     6490        @Colour@ pants; $\C{// type defined same level}$
     6491        Face looks[10]; $\C{// type defined same level}$
    64376492};
    6438 ®Colour® c = R; §\C{// type/enum defined same level}§
    6439 Person®.Colour® pc = Person®.®R;§\C{// type/enum defined inside}§
    6440 Person®.®Face pretty; §\C{// type defined inside}\CRT§
     6493@Colour@ c = R; $\C{// type/enum defined same level}$
     6494Person@.Colour@ pc = Person@.@R;$\C{// type/enum defined inside}$
     6495Person@.@Face pretty; $\C{// type defined inside}\CRT$
    64416496\end{cfa}
    64426497In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing structure, \ie the nested types are hoisted to the scope of the outer-most type, which is not useful and confusing.
     
    64556510\item[Difficulty of converting:] Semantic transformation. To make the struct type name visible in the scope of the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing struct is defined. Example:
    64566511\begin{cfa}
    6457 struct Y; §\C{// struct Y and struct X are at the same scope}§
     6512struct Y; $\C{// struct Y and struct X are at the same scope}$
    64586513struct X {
    64596514        struct Y { /* ... */ } y;
     
    64706525\begin{cfa}
    64716526void foo() {
    6472         int * b = malloc( sizeof(int) ); §\C{// implicitly convert void * to int *}§
    6473         char * c = b; §\C{// implicitly convert int * to void *, and then void * to char *}§
     6527        int * b = malloc( sizeof(int) ); $\C{// implicitly convert void * to int *}$
     6528        char * c = b; $\C{// implicitly convert int * to void *, and then void * to char *}$
    64746529}
    64756530\end{cfa}
    64766531\item[Rationale:] increase type safety
    64776532\item[Effect on original feature:] deletion of semantically well-defined feature.
    6478 \item[Difficulty of converting:] requires adding a cast (see \VRef{s:StorageManagement} for better alternatives):
     6533\item[Difficulty of converting:] requires adding a cast \see{\VRef{s:StorageManagement} for better alternatives}:
    64796534\begin{cfa}
    64806535        int * b = (int *)malloc( sizeof(int) );
     
    65866641\end{cquote}
    65876642For the prescribed head-files, \CFA uses header interposition to wraps these includes in an ©extern "C"©;
    6588 hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}).
     6643hence, names in these include files are not mangled\index{mangling!name} \see{\VRef{s:Interoperability}}.
    65896644All other C header files must be explicitly wrapped in ©extern "C"© to prevent name mangling.
    65906645This approach is different from \Index*[C++]{\CC{}} where the name-mangling issue is handled internally in C header-files through checks for preprocessor variable ©__cplusplus©, which adds appropriate ©extern "C"© qualifiers.
     
    66496704Type-safe allocation is provided for all C allocation routines and new \CFA allocation routines, \eg in
    66506705\begin{cfa}
    6651 int * ip = (int *)malloc( sizeof(int) );                §\C{// C}§
    6652 int * ip = malloc();                                                    §\C{// \CFA type-safe version of C malloc}§
    6653 int * ip = alloc();                                                             §\C{// \CFA type-safe uniform alloc}§
     6706int * ip = (int *)malloc( sizeof(int) );                $\C{// C}$
     6707int * ip = malloc();                                                    $\C{// \CFA type-safe version of C malloc}$
     6708int * ip = alloc();                                                             $\C{// \CFA type-safe uniform alloc}$
    66546709\end{cfa}
    66556710the latter two allocations determine the allocation size from the type of ©p© (©int©) and cast the pointer to the allocated storage to ©int *©.
     
    66586713\begin{cfa}
    66596714struct S { int i; } __attribute__(( aligned( 128 ) )); // cache-line alignment
    6660 S * sp = malloc();                                                              §\C{// honour type alignment}§
     6715S * sp = malloc();                                                              $\C{// honour type alignment}$
    66616716\end{cfa}
    66626717the storage allocation is implicitly aligned to 128 rather than the default 16.
     
    66736728\CFA memory management extends allocation to support constructors for initialization of allocated storage, \eg in
    66746729\begin{cfa}
    6675 struct S { int i; };                                                    §\C{// cache-line aglinment}§
     6730struct S { int i; };                                                    $\C{// cache-line alignment}$
    66766731void ?{}( S & s, int i ) { s.i = i; }
    66776732// assume ?|? operator for printing an S
    66786733
    6679 S & sp = *®new®( 3 );                                                   §\C{// call constructor after allocation}§
     6734S & sp = *@new@( 3 );                                                   $\C{// call constructor after allocation}$
    66806735sout | sp.i;
    6681 ®delete®( &sp );
    6682 
    6683 S * spa = ®anew®( 10, 5 );                                              §\C{// allocate array and initialize each array element}§
     6736@delete@( &sp );
     6737
     6738S * spa = @anew@( 10, 5 );                                              $\C{// allocate array and initialize each array element}$
    66846739for ( i; 10 ) sout | spa[i] | nonl;
    66856740sout | nl;
    6686 ®adelete®( 10, spa );
     6741@adelete@( 10, spa );
    66876742\end{cfa}
    66886743Allocation routines ©new©/©anew© allocate a variable/array and initialize storage using the allocated type's constructor.
     
    66936748extern "C" {
    66946749        // C unsafe allocation
    6695         void * malloc( size_t size );§\indexc{malloc}§
    6696         void * calloc( size_t dim, size_t size );§\indexc{calloc}§
    6697         void * realloc( void * ptr, size_t size );§\indexc{realloc}§
    6698         void * memalign( size_t align, size_t size );§\indexc{memalign}§
    6699         void * aligned_alloc( size_t align, size_t size );§\indexc{aligned_alloc}§
    6700         int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
    6701         void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );§\indexc{cmemalign}§ // CFA
     6750        void * malloc( size_t size );$\indexc{malloc}$
     6751        void * calloc( size_t dim, size_t size );$\indexc{calloc}$
     6752        void * realloc( void * ptr, size_t size );$\indexc{realloc}$
     6753        void * memalign( size_t align, size_t size );$\indexc{memalign}$
     6754        void * aligned_alloc( size_t align, size_t size );$\indexc{aligned_alloc}$
     6755        int posix_memalign( void ** ptr, size_t align, size_t size );$\indexc{posix_memalign}$
     6756        void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );$\indexc{cmemalign}$ // CFA
    67026757
    67036758        // C unsafe initialization/copy
    6704         void * memset( void * dest, int c, size_t size );§\indexc{memset}§
    6705         void * memcpy( void * dest, const void * src, size_t size );§\indexc{memcpy}§
     6759        void * memset( void * dest, int c, size_t size );$\indexc{memset}$
     6760        void * memcpy( void * dest, const void * src, size_t size );$\indexc{memcpy}$
    67066761}
    67076762
     
    67096764
    67106765forall( dtype T | sized(T) ) {
    6711         // §\CFA§ safe equivalents, i.e., implicit size specification
     6766        // $\CFA$ safe equivalents, i.e., implicit size specification
    67126767        T * malloc( void );
    67136768        T * calloc( size_t dim );
     
    67186773        int posix_memalign( T ** ptr, size_t align );
    67196774
    6720         // §\CFA§ safe general allocation, fill, resize, alignment, array
    6721         T * alloc( void );§\indexc{alloc}§                                      §\C[3.5in]{// variable, T size}§
    6722         T * alloc( size_t dim );                                                        §\C{// array[dim], T size elements}§
    6723         T * alloc( T ptr[], size_t dim );                                       §\C{// realloc array[dim], T size elements}§
    6724 
    6725         T * alloc_set( char fill );§\indexc{alloc_set}§         §\C{// variable, T size, fill bytes with value}§
    6726         T * alloc_set( T fill );                                                        §\C{// variable, T size, fill with value}§
    6727         T * alloc_set( size_t dim, char fill );                         §\C{// array[dim], T size elements, fill bytes with value}§
    6728         T * alloc_set( size_t dim, T fill );                            §\C{// array[dim], T size elements, fill elements with value}§
    6729         T * alloc_set( size_t dim, const T fill[] );            §\C{// array[dim], T size elements, fill elements with array}§
    6730         T * alloc_set( T ptr[], size_t dim, char fill );        §\C{// realloc array[dim], T size elements, fill bytes with value}§
    6731 
    6732         T * alloc_align( size_t align );                                        §\C{// aligned variable, T size}§
    6733         T * alloc_align( size_t align, size_t dim );            §\C{// aligned array[dim], T size elements}§
    6734         T * alloc_align( T ptr[], size_t align );                       §\C{// realloc new aligned array}§
    6735         T * alloc_align( T ptr[], size_t align, size_t dim ); §\C{// realloc new aligned array[dim]}§
    6736 
    6737         T * alloc_align_set( size_t align, char fill );         §\C{// aligned variable, T size, fill bytes with value}§
    6738         T * alloc_align_set( size_t align, T fill );            §\C{// aligned variable, T size, fill with value}§
    6739         T * alloc_align_set( size_t align, size_t dim, char fill ); §\C{// aligned array[dim], T size elements, fill bytes with value}§
    6740         T * alloc_align_set( size_t align, size_t dim, T fill ); §\C{// aligned array[dim], T size elements, fill elements with value}§
    6741         T * alloc_align_set( size_t align, size_t dim, const T fill[] ); §\C{// aligned array[dim], T size elements, fill elements with array}§
    6742         T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ); §\C{// realloc new aligned array[dim], fill new bytes with value}§
    6743 
    6744         // §\CFA§ safe initialization/copy, i.e., implicit size specification
    6745         T * memset( T * dest, char fill );§\indexc{memset}§
    6746         T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
    6747 
    6748         // §\CFA§ safe initialization/copy, i.e., implicit size specification, array types
     6775        // $\CFA$ safe general allocation, fill, resize, alignment, array
     6776        T * alloc( void );$\indexc{alloc}$                                      $\C[3.5in]{// variable, T size}$
     6777        T * alloc( size_t dim );                                                        $\C{// array[dim], T size elements}$
     6778        T * alloc( T ptr[], size_t dim );                                       $\C{// realloc array[dim], T size elements}$
     6779
     6780        T * alloc_set( char fill );$\indexc{alloc_set}$         $\C{// variable, T size, fill bytes with value}$
     6781        T * alloc_set( T fill );                                                        $\C{// variable, T size, fill with value}$
     6782        T * alloc_set( size_t dim, char fill );                         $\C{// array[dim], T size elements, fill bytes with value}$
     6783        T * alloc_set( size_t dim, T fill );                            $\C{// array[dim], T size elements, fill elements with value}$
     6784        T * alloc_set( size_t dim, const T fill[] );            $\C{// array[dim], T size elements, fill elements with array}$
     6785        T * alloc_set( T ptr[], size_t dim, char fill );        $\C{// realloc array[dim], T size elements, fill bytes with value}$
     6786
     6787        T * alloc_align( size_t align );                                        $\C{// aligned variable, T size}$
     6788        T * alloc_align( size_t align, size_t dim );            $\C{// aligned array[dim], T size elements}$
     6789        T * alloc_align( T ptr[], size_t align );                       $\C{// realloc new aligned array}$
     6790        T * alloc_align( T ptr[], size_t align, size_t dim ); $\C{// realloc new aligned array[dim]}$
     6791
     6792        T * alloc_align_set( size_t align, char fill );         $\C{// aligned variable, T size, fill bytes with value}$
     6793        T * alloc_align_set( size_t align, T fill );            $\C{// aligned variable, T size, fill with value}$
     6794        T * alloc_align_set( size_t align, size_t dim, char fill ); $\C{// aligned array[dim], T size elements, fill bytes with value}$
     6795        T * alloc_align_set( size_t align, size_t dim, T fill ); $\C{// aligned array[dim], T size elements, fill elements with value}$
     6796        T * alloc_align_set( size_t align, size_t dim, const T fill[] ); $\C{// aligned array[dim], T size elements, fill elements with array}$
     6797        T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ); $\C{// realloc new aligned array[dim], fill new bytes with value}$
     6798
     6799        // $\CFA$ safe initialization/copy, i.e., implicit size specification
     6800        T * memset( T * dest, char fill );$\indexc{memset}$
     6801        T * memcpy( T * dest, const T * src );$\indexc{memcpy}$
     6802
     6803        // $\CFA$ safe initialization/copy, i.e., implicit size specification, array types
    67496804        T * amemset( T dest[], char fill, size_t dim );
    67506805        T * amemcpy( T dest[], const T src[], size_t dim );
    67516806}
    67526807
    6753 // §\CFA§ allocation/deallocation and constructor/destructor, non-array types
    6754 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );§\indexc{new}§
    6755 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );§\indexc{delete}§
     6808// $\CFA$ allocation/deallocation and constructor/destructor, non-array types
     6809forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );$\indexc{new}$
     6810forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );$\indexc{delete}$
    67566811forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } )
    67576812  void delete( T * ptr, Params rest );
    67586813
    6759 // §\CFA§ allocation/deallocation and constructor/destructor, array types
    6760 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
    6761 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
     6814// $\CFA$ allocation/deallocation and constructor/destructor, array types
     6815forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );$\indexc{anew}$
     6816forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );$\indexc{adelete}$
    67626817forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } )
    67636818  void adelete( size_t dim, T arr[], Params rest );
     
    67696824\leavevmode
    67706825\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6771 int ato( const char * ptr );§\indexc{ato}§
     6826int ato( const char * ptr );$\indexc{ato}$
    67726827unsigned int ato( const char * ptr );
    67736828long int ato( const char * ptr );
     
    68016856\leavevmode
    68026857\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6803 forall( otype T | { int ?<?( T, T ); } ) §\C{// location}§
    6804 T * bsearch( T key, const T * arr, size_t dim );§\indexc{bsearch}§
    6805 
    6806 forall( otype T | { int ?<?( T, T ); } ) §\C{// position}§
     6858forall( otype T | { int ?<?( T, T ); } ) $\C{// location}$
     6859T * bsearch( T key, const T * arr, size_t dim );$\indexc{bsearch}$
     6860
     6861forall( otype T | { int ?<?( T, T ); } ) $\C{// position}$
    68076862unsigned int bsearch( T key, const T * arr, size_t dim );
    68086863
    68096864forall( otype T | { int ?<?( T, T ); } )
    6810 void qsort( const T * arr, size_t dim );§\indexc{qsort}§
     6865void qsort( const T * arr, size_t dim );$\indexc{qsort}$
    68116866
    68126867forall( otype E | { int ?<?( E, E ); } ) {
    6813         E * bsearch( E key, const E * vals, size_t dim );§\indexc{bsearch}§ §\C{// location}§
    6814         size_t bsearch( E key, const E * vals, size_t dim );§\C{// position}§
    6815         E * bsearchl( E key, const E * vals, size_t dim );§\indexc{bsearchl}§
     6868        E * bsearch( E key, const E * vals, size_t dim );$\indexc{bsearch}$ $\C{// location}$
     6869        size_t bsearch( E key, const E * vals, size_t dim );$\C{// position}$
     6870        E * bsearchl( E key, const E * vals, size_t dim );$\indexc{bsearchl}$
    68166871        size_t bsearchl( E key, const E * vals, size_t dim );
    6817         E * bsearchu( E key, const E * vals, size_t dim );§\indexc{bsearchu}§
     6872        E * bsearchu( E key, const E * vals, size_t dim );$\indexc{bsearchu}$
    68186873        size_t bsearchu( E key, const E * vals, size_t dim );
    68196874}
     
    68296884
    68306885forall( otype E | { int ?<?( E, E ); } ) {
    6831         void qsort( E * vals, size_t dim );§\indexc{qsort}§
     6886        void qsort( E * vals, size_t dim );$\indexc{qsort}$
    68326887}
    68336888\end{cfa}
     
    68386893\leavevmode
    68396894\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6840 unsigned char abs( signed char );§\indexc{abs}§
     6895unsigned char abs( signed char );$\indexc{abs}$
    68416896int abs( int );
    68426897unsigned long int abs( long int );
     
    68576912\leavevmode
    68586913\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6859 void srandom( unsigned int seed );§\indexc{srandom}§
    6860 char random( void );§\indexc{random}§
    6861 char random( char u ); §\C{// [0,u)}§
    6862 char random( char l, char u ); §\C{// [l,u)}§
     6914void srandom( unsigned int seed );$\indexc{srandom}$
     6915char random( void );$\indexc{random}$
     6916char random( char u ); $\C{// [0,u)}$
     6917char random( char l, char u ); $\C{// [l,u)}$
    68636918int random( void );
    6864 int random( int u ); §\C{// [0,u)}§
    6865 int random( int l, int u ); §\C{// [l,u)}§
     6919int random( int u ); $\C{// [0,u)}$
     6920int random( int l, int u ); $\C{// [l,u)}$
    68666921unsigned int random( void );
    6867 unsigned int random( unsigned int u ); §\C{// [0,u)}§
    6868 unsigned int random( unsigned int l, unsigned int u ); §\C{// [l,u)}§
     6922unsigned int random( unsigned int u ); $\C{// [0,u)}$
     6923unsigned int random( unsigned int l, unsigned int u ); $\C{// [l,u)}$
    68696924long int random( void );
    6870 long int random( long int u ); §\C{// [0,u)}§
    6871 long int random( long int l, long int u ); §\C{// [l,u)}§
     6925long int random( long int u ); $\C{// [0,u)}$
     6926long int random( long int l, long int u ); $\C{// [l,u)}$
    68726927unsigned long int random( void );
    6873 unsigned long int random( unsigned long int u ); §\C{// [0,u)}§
    6874 unsigned long int random( unsigned long int l, unsigned long int u ); §\C{// [l,u)}§
    6875 float random( void );                                            §\C{// [0.0, 1.0)}§
    6876 double random( void );                                           §\C{// [0.0, 1.0)}§
    6877 float _Complex random( void );                           §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
    6878 double _Complex random( void );                          §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
    6879 long double _Complex random( void );             §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
     6928unsigned long int random( unsigned long int u ); $\C{// [0,u)}$
     6929unsigned long int random( unsigned long int l, unsigned long int u ); $\C{// [l,u)}$
     6930float random( void );                                            $\C{// [0.0, 1.0)}$
     6931double random( void );                                           $\C{// [0.0, 1.0)}$
     6932float _Complex random( void );                           $\C{// [0.0, 1.0)+[0.0, 1.0)i}$
     6933double _Complex random( void );                          $\C{// [0.0, 1.0)+[0.0, 1.0)i}$
     6934long double _Complex random( void );             $\C{// [0.0, 1.0)+[0.0, 1.0)i}$
    68806935\end{cfa}
    68816936
     
    68856940\leavevmode
    68866941\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6887 forall( otype T | { int ?<?( T, T ); } ) T min( T t1, T t2 );§\indexc{min}§
    6888 forall( otype T | { int ?>?( T, T ); } ) T max( T t1, T t2 );§\indexc{max}§
    6889 forall( otype T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );§\indexc{clamp}§
    6890 forall( otype T ) void swap( T * t1, T * t2 );§\indexc{swap}§
     6942forall( otype T | { int ?<?( T, T ); } ) T min( T t1, T t2 );$\indexc{min}$
     6943forall( otype T | { int ?>?( T, T ); } ) T max( T t1, T t2 );$\indexc{max}$
     6944forall( otype T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );$\indexc{clamp}$
     6945forall( otype T ) void swap( T * t1, T * t2 );$\indexc{swap}$
    68916946\end{cfa}
    68926947
     
    69026957\leavevmode
    69036958\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6904 float ?%?( float, float );§\indexc{fmod}§
     6959float ?%?( float, float );$\indexc{fmod}$
    69056960float fmod( float, float );
    69066961double ?%?( double, double );
     
    69096964long double fmod( long double, long double );
    69106965
    6911 float remainder( float, float );§\indexc{remainder}§
     6966float remainder( float, float );$\indexc{remainder}$
    69126967double remainder( double, double );
    69136968long double remainder( long double, long double );
    69146969
    6915 float remquo( float, float, int * );§\indexc{remquo}§
     6970float remquo( float, float, int * );$\indexc{remquo}$
    69166971double remquo( double, double, int * );
    69176972long double remquo( long double, long double, int * );
     
    69206975[ int, long double ] remquo( long double, long double );
    69216976
    6922 float div( float, float, int * );§\indexc{div}§ §\C{// alternative name for remquo}§
     6977float div( float, float, int * );$\indexc{div}$ $\C{// alternative name for remquo}$
    69236978double div( double, double, int * );
    69246979long double div( long double, long double, int * );
     
    69276982[ int, long double ] div( long double, long double );
    69286983
    6929 float fma( float, float, float );§\indexc{fma}§
     6984float fma( float, float, float );$\indexc{fma}$
    69306985double fma( double, double, double );
    69316986long double fma( long double, long double, long double );
    69326987
    6933 float fdim( float, float );§\indexc{fdim}§
     6988float fdim( float, float );$\indexc{fdim}$
    69346989double fdim( double, double );
    69356990long double fdim( long double, long double );
    69366991
    6937 float nan( const char * );§\indexc{nan}§
     6992float nan( const char * );$\indexc{nan}$
    69386993double nan( const char * );
    69396994long double nan( const char * );
     
    69457000\leavevmode
    69467001\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6947 float exp( float );§\indexc{exp}§
     7002float exp( float );$\indexc{exp}$
    69487003double exp( double );
    69497004long double exp( long double );
     
    69527007long double _Complex exp( long double _Complex );
    69537008
    6954 float exp2( float );§\indexc{exp2}§
     7009float exp2( float );$\indexc{exp2}$
    69557010double exp2( double );
    69567011long double exp2( long double );
     
    69597014// long double _Complex exp2( long double _Complex );
    69607015
    6961 float expm1( float );§\indexc{expm1}§
     7016float expm1( float );$\indexc{expm1}$
    69627017double expm1( double );
    69637018long double expm1( long double );
    69647019
    6965 float pow( float, float );§\indexc{pow}§
     7020float pow( float, float );$\indexc{pow}$
    69667021double pow( double, double );
    69677022long double pow( long double, long double );
     
    69767031\leavevmode
    69777032\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6978 float log( float );§\indexc{log}§
     7033float log( float );$\indexc{log}$
    69797034double log( double );
    69807035long double log( long double );
     
    69837038long double _Complex log( long double _Complex );
    69847039
    6985 float log2( float );§\indexc{log2}§
     7040float log2( float );$\indexc{log2}$
    69867041double log2( double );
    69877042long double log2( long double );
     
    69907045// long double _Complex log2( long double _Complex );
    69917046
    6992 float log10( float );§\indexc{log10}§
     7047float log10( float );$\indexc{log10}$
    69937048double log10( double );
    69947049long double log10( long double );
     
    69977052// long double _Complex log10( long double _Complex );
    69987053
    6999 float log1p( float );§\indexc{log1p}§
     7054float log1p( float );$\indexc{log1p}$
    70007055double log1p( double );
    70017056long double log1p( long double );
    70027057
    7003 int ilogb( float );§\indexc{ilogb}§
     7058int ilogb( float );$\indexc{ilogb}$
    70047059int ilogb( double );
    70057060int ilogb( long double );
    70067061
    7007 float logb( float );§\indexc{logb}§
     7062float logb( float );$\indexc{logb}$
    70087063double logb( double );
    70097064long double logb( long double );
    70107065
    7011 float sqrt( float );§\indexc{sqrt}§
     7066float sqrt( float );$\indexc{sqrt}$
    70127067double sqrt( double );
    70137068long double sqrt( long double );
     
    70167071long double _Complex sqrt( long double _Complex );
    70177072
    7018 float cbrt( float );§\indexc{cbrt}§
     7073float cbrt( float );$\indexc{cbrt}$
    70197074double cbrt( double );
    70207075long double cbrt( long double );
    70217076
    7022 float hypot( float, float );§\indexc{hypot}§
     7077float hypot( float, float );$\indexc{hypot}$
    70237078double hypot( double, double );
    70247079long double hypot( long double, long double );
     
    70307085\leavevmode
    70317086\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7032 float sin( float );§\indexc{sin}§
     7087float sin( float );$\indexc{sin}$
    70337088double sin( double );
    70347089long double sin( long double );
     
    70377092long double _Complex sin( long double _Complex );
    70387093
    7039 float cos( float );§\indexc{cos}§
     7094float cos( float );$\indexc{cos}$
    70407095double cos( double );
    70417096long double cos( long double );
     
    70447099long double _Complex cos( long double _Complex );
    70457100
    7046 float tan( float );§\indexc{tan}§
     7101float tan( float );$\indexc{tan}$
    70477102double tan( double );
    70487103long double tan( long double );
     
    70517106long double _Complex tan( long double _Complex );
    70527107
    7053 float asin( float );§\indexc{asin}§
     7108float asin( float );$\indexc{asin}$
    70547109double asin( double );
    70557110long double asin( long double );
     
    70587113long double _Complex asin( long double _Complex );
    70597114
    7060 float acos( float );§\indexc{acos}§
     7115float acos( float );$\indexc{acos}$
    70617116double acos( double );
    70627117long double acos( long double );
     
    70657120long double _Complex acos( long double _Complex );
    70667121
    7067 float atan( float );§\indexc{atan}§
     7122float atan( float );$\indexc{atan}$
    70687123double atan( double );
    70697124long double atan( long double );
     
    70727127long double _Complex atan( long double _Complex );
    70737128
    7074 float atan2( float, float );§\indexc{atan2}§
     7129float atan2( float, float );$\indexc{atan2}$
    70757130double atan2( double, double );
    70767131long double atan2( long double, long double );
    70777132
    7078 float atan( float, float ); §\C{// alternative name for atan2}§
    7079 double atan( double, double );§\indexc{atan}§
     7133float atan( float, float ); $\C{// alternative name for atan2}$
     7134double atan( double, double );$\indexc{atan}$
    70807135long double atan( long double, long double );
    70817136\end{cfa}
     
    70867141\leavevmode
    70877142\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7088 float sinh( float );§\indexc{sinh}§
     7143float sinh( float );$\indexc{sinh}$
    70897144double sinh( double );
    70907145long double sinh( long double );
     
    70937148long double _Complex sinh( long double _Complex );
    70947149
    7095 float cosh( float );§\indexc{cosh}§
     7150float cosh( float );$\indexc{cosh}$
    70967151double cosh( double );
    70977152long double cosh( long double );
     
    71007155long double _Complex cosh( long double _Complex );
    71017156
    7102 float tanh( float );§\indexc{tanh}§
     7157float tanh( float );$\indexc{tanh}$
    71037158double tanh( double );
    71047159long double tanh( long double );
     
    71077162long double _Complex tanh( long double _Complex );
    71087163
    7109 float asinh( float );§\indexc{asinh}§
     7164float asinh( float );$\indexc{asinh}$
    71107165double asinh( double );
    71117166long double asinh( long double );
     
    71147169long double _Complex asinh( long double _Complex );
    71157170
    7116 float acosh( float );§\indexc{acosh}§
     7171float acosh( float );$\indexc{acosh}$
    71177172double acosh( double );
    71187173long double acosh( long double );
     
    71217176long double _Complex acosh( long double _Complex );
    71227177
    7123 float atanh( float );§\indexc{atanh}§
     7178float atanh( float );$\indexc{atanh}$
    71247179double atanh( double );
    71257180long double atanh( long double );
     
    71347189\leavevmode
    71357190\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7136 float erf( float );§\indexc{erf}§
     7191float erf( float );$\indexc{erf}$
    71377192double erf( double );
    71387193long double erf( long double );
     
    71417196long double _Complex erf( long double _Complex );
    71427197
    7143 float erfc( float );§\indexc{erfc}§
     7198float erfc( float );$\indexc{erfc}$
    71447199double erfc( double );
    71457200long double erfc( long double );
     
    71487203long double _Complex erfc( long double _Complex );
    71497204
    7150 float lgamma( float );§\indexc{lgamma}§
     7205float lgamma( float );$\indexc{lgamma}$
    71517206double lgamma( double );
    71527207long double lgamma( long double );
     
    71557210long double lgamma( long double, int * );
    71567211
    7157 float tgamma( float );§\indexc{tgamma}§
     7212float tgamma( float );$\indexc{tgamma}$
    71587213double tgamma( double );
    71597214long double tgamma( long double );
     
    71657220\leavevmode
    71667221\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7167 float floor( float );§\indexc{floor}§
     7222float floor( float );$\indexc{floor}$
    71687223double floor( double );
    71697224long double floor( long double );
    71707225
    7171 float ceil( float );§\indexc{ceil}§
     7226float ceil( float );$\indexc{ceil}$
    71727227double ceil( double );
    71737228long double ceil( long double );
    71747229
    7175 float trunc( float );§\indexc{trunc}§
     7230float trunc( float );$\indexc{trunc}$
    71767231double trunc( double );
    71777232long double trunc( long double );
    71787233
    7179 float rint( float );§\indexc{rint}§
     7234float rint( float );$\indexc{rint}$
    71807235long double rint( long double );
    71817236long int rint( float );
     
    71867241long long int rint( long double );
    71877242
    7188 long int lrint( float );§\indexc{lrint}§
     7243long int lrint( float );$\indexc{lrint}$
    71897244long int lrint( double );
    71907245long int lrint( long double );
     
    71937248long long int llrint( long double );
    71947249
    7195 float nearbyint( float );§\indexc{nearbyint}§
     7250float nearbyint( float );$\indexc{nearbyint}$
    71967251double nearbyint( double );
    71977252long double nearbyint( long double );
    71987253
    7199 float round( float );§\indexc{round}§
     7254float round( float );$\indexc{round}$
    72007255long double round( long double );
    72017256long int round( float );
     
    72067261long long int round( long double );
    72077262
    7208 long int lround( float );§\indexc{lround}§
     7263long int lround( float );$\indexc{lround}$
    72097264long int lround( double );
    72107265long int lround( long double );
     
    72197274\leavevmode
    72207275\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7221 float copysign( float, float );§\indexc{copysign}§
     7276float copysign( float, float );$\indexc{copysign}$
    72227277double copysign( double, double );
    72237278long double copysign( long double, long double );
    72247279
    7225 float frexp( float, int * );§\indexc{frexp}§
     7280float frexp( float, int * );$\indexc{frexp}$
    72267281double frexp( double, int * );
    72277282long double frexp( long double, int * );
    72287283
    7229 float ldexp( float, int );§\indexc{ldexp}§
     7284float ldexp( float, int );$\indexc{ldexp}$
    72307285double ldexp( double, int );
    72317286long double ldexp( long double, int );
    72327287
    7233 [ float, float ] modf( float );§\indexc{modf}§
     7288[ float, float ] modf( float );$\indexc{modf}$
    72347289float modf( float, float * );
    72357290[ double, double ] modf( double );
     
    72387293long double modf( long double, long double * );
    72397294
    7240 float nextafter( float, float );§\indexc{nextafter}§
     7295float nextafter( float, float );$\indexc{nextafter}$
    72417296double nextafter( double, double );
    72427297long double nextafter( long double, long double );
    72437298
    7244 float nexttoward( float, long double );§\indexc{nexttoward}§
     7299float nexttoward( float, long double );$\indexc{nexttoward}$
    72457300double nexttoward( double, long double );
    72467301long double nexttoward( long double, long double );
    72477302
    7248 float scalbn( float, int );§\indexc{scalbn}§
     7303float scalbn( float, int );$\indexc{scalbn}$
    72497304double scalbn( double, int );
    72507305long double scalbn( long double, int );
    72517306
    7252 float scalbln( float, long int );§\indexc{scalbln}§
     7307float scalbln( float, long int );$\indexc{scalbln}$
    72537308double scalbln( double, long int );
    72547309long double scalbln( long double, long int );
     
    72677322\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    72687323struct Duration {
    7269         int64_t tv; §\C{// nanoseconds}§
     7324        int64_t tv; $\C{// nanoseconds}$
    72707325};
    72717326
     
    73977452\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    73987453struct Time {
    7399         uint64_t tv; §\C{// nanoseconds since UNIX epoch}§
     7454        uint64_t tv; $\C{// nanoseconds since UNIX epoch}$
    74007455};
    74017456
     
    74687523\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    74697524struct Clock {
    7470         Duration offset; §\C{// for virtual clock: contains offset from real-time}§
    7471         int clocktype; §\C{// implementation only -1 (virtual), CLOCK\_REALTIME}§
     7525        Duration offset; $\C{// for virtual clock: contains offset from real-time}$
     7526        int clocktype; $\C{// implementation only -1 (virtual), CLOCK\_REALTIME}$
    74727527};
    74737528
     
    74777532void ?{}( Clock & clk, Duration adj );
    74787533
    7479 Duration getResNsec(); §\C{// with nanoseconds}§
    7480 Duration getRes(); §\C{// without nanoseconds}§
    7481 
    7482 Time getTimeNsec(); §\C{// with nanoseconds}§
    7483 Time getTime(); §\C{// without nanoseconds}§
     7534Duration getResNsec(); $\C{// with nanoseconds}$
     7535Duration getRes(); $\C{// without nanoseconds}$
     7536
     7537Time getTimeNsec(); $\C{// with nanoseconds}$
     7538Time getTime(); $\C{// without nanoseconds}$
    74847539Time getTime( Clock & clk );
    74857540Time ?()( Clock & clk );
     
    74977552
    74987553\begin{cfa}
    7499 void ?{}( Int * this ); §\C{// constructor/destructor}§
     7554void ?{}( Int * this ); $\C{// constructor/destructor}$
    75007555void ?{}( Int * this, Int init );
    75017556void ?{}( Int * this, zero_t );
     
    75067561void ^?{}( Int * this );
    75077562
    7508 Int ?=?( Int * lhs, Int rhs ); §\C{// assignment}§
     7563Int ?=?( Int * lhs, Int rhs ); $\C{// assignment}$
    75097564Int ?=?( Int * lhs, long int rhs );
    75107565Int ?=?( Int * lhs, unsigned long int rhs );
     
    75237578unsigned long int narrow( Int val );
    75247579
    7525 int ?==?( Int oper1, Int oper2 ); §\C{// comparison}§
     7580int ?==?( Int oper1, Int oper2 ); $\C{// comparison}$
    75267581int ?==?( Int oper1, long int oper2 );
    75277582int ?==?( long int oper2, Int oper1 );
     
    75597614int ?>=?( unsigned long int oper1, Int oper2 );
    75607615
    7561 Int +?( Int oper ); §\C{// arithmetic}§
     7616Int +?( Int oper ); $\C{// arithmetic}$
    75627617Int -?( Int oper );
    75637618Int ~?( Int oper );
     
    76417696Int ?>>=?( Int * lhs, mp_bitcnt_t shift );
    76427697
    7643 Int abs( Int oper ); §\C{// number functions}§
     7698Int abs( Int oper ); $\C{// number functions}$
    76447699Int fact( unsigned long int N );
    76457700Int gcd( Int oper1, Int oper2 );
     
    76537708Int sqrt( Int oper );
    76547709
    7655 forall( dtype istype | istream( istype ) ) istype * ?|?( istype * is, Int * mp );  §\C{// I/O}§
     7710forall( dtype istype | istream( istype ) ) istype * ?|?( istype * is, Int * mp );  $\C{// I/O}$
    76567711forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype * os, Int mp );
    76577712\end{cfa}
     
    76647719\hline
    76657720\begin{cfa}
    7666 #include <gmp>§\indexc{gmp}§
     7721#include <gmp>$\indexc{gmp}$
    76677722int main( void ) {
    76687723        sout | "Factorial Numbers";
     
    76787733&
    76797734\begin{cfa}
    7680 #include <gmp.h>§\indexc{gmp.h}§
     7735#include <gmp.h>$\indexc{gmp.h}$
    76817736int main( void ) {
    7682         ®gmp_printf®( "Factorial Numbers\n" );
    7683         ®mpz_t® fact;
    7684         ®mpz_init_set_ui®( fact, 1 );
    7685         ®gmp_printf®( "%d %Zd\n", 0, fact );
     7737        @gmp_printf@( "Factorial Numbers\n" );
     7738        @mpz_t@ fact;
     7739        @mpz_init_set_ui@( fact, 1 );
     7740        @gmp_printf@( "%d %Zd\n", 0, fact );
    76867741        for ( unsigned int i = 1; i <= 40; i += 1 ) {
    7687                 ®mpz_mul_ui®( fact, fact, i );
    7688                 ®gmp_printf®( "%d %Zd\n", i, fact );
     7742                @mpz_mul_ui@( fact, fact, i );
     7743                @gmp_printf@( "%d %Zd\n", i, fact );
    76897744        }
    76907745}
     
    77517806\begin{cfa}[belowskip=0pt]
    77527807// implementation
    7753 struct Rational {§\indexc{Rational}§
    7754         long int numerator, denominator; §\C{// invariant: denominator > 0}§
     7808struct Rational {$\indexc{Rational}$
     7809        long int numerator, denominator; $\C{// invariant: denominator > 0}$
    77557810}; // Rational
    77567811
    7757 Rational rational(); §\C{// constructors}§
     7812Rational rational(); $\C{// constructors}$
    77587813Rational rational( long int n );
    77597814Rational rational( long int n, long int d );
     
    77617816void ?{}( Rational * r, one_t );
    77627817
    7763 long int numerator( Rational r ); §\C{// numerator/denominator getter/setter}§
     7818long int numerator( Rational r ); $\C{// numerator/denominator getter/setter}$
    77647819long int numerator( Rational r, long int n );
    77657820long int denominator( Rational r );
    77667821long int denominator( Rational r, long int d );
    77677822
    7768 int ?==?( Rational l, Rational r ); §\C{// comparison}§
     7823int ?==?( Rational l, Rational r ); $\C{// comparison}$
    77697824int ?!=?( Rational l, Rational r );
    77707825int ?<?( Rational l, Rational r );
     
    77737828int ?>=?( Rational l, Rational r );
    77747829
    7775 Rational -?( Rational r ); §\C{// arithmetic}§
     7830Rational -?( Rational r ); $\C{// arithmetic}$
    77767831Rational ?+?( Rational l, Rational r );
    77777832Rational ?-?( Rational l, Rational r );
     
    77797834Rational ?/?( Rational l, Rational r );
    77807835
    7781 double widen( Rational r ); §\C{// conversion}§
     7836double widen( Rational r ); $\C{// conversion}$
    77827837Rational narrow( double f, long int md );
    77837838
  • src/main.cc

    rd4a4b17 rf4eb705  
    99// Author           : Peter Buhr and Rob Schluntz
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Dec  7 15:29:00 2020
    13 // Update Count     : 639
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Feb  8 21:10:16 2021
     13// Update Count     : 642
    1414//
    1515
     
    492492
    493493static const char * description[] = {
    494         "diagnostic color: never, always, or auto.",            // -c
     494        "diagnostic color: never, always, auto",                        // -c
    495495        "wait for gdb to attach",                                                       // -g
    496         "print help message",                                                           // -h
     496        "print translator help message",                                        // -h
    497497        "generate libcfa.c",                                                            // -l
    498498        "generate line marks",                                                          // -L
     
    500500        "do not generate line marks",                                           // -N
    501501        "do not read prelude",                                                          // -n
    502         "generate prototypes for prelude functions",            // -p
     502        "do not generate prelude prototypes => prelude not printed", // -p
    503503        "only print deterministic output",                  // -d
    504504        "Use the old-ast",                                                                      // -O
     
    506506        "print",                                                                                        // -P
    507507        "<directory> prelude directory for debug/nodebug",      // no flag
    508         "<option-list> enable profiling information:\n          counters,heap,time,all,none", // -S
     508        "<option-list> enable profiling information: counters, heap, time, all, none", // -S
    509509        "building cfa standard lib",                                            // -t
    510510        "",                                                                                                     // -w
Note: See TracChangeset for help on using the changeset viewer.