Changes in / [f4eb705:d4a4b17]


Ignore:
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.tex

    rf4eb705 rd4a4b17  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Feb  8 21:45:41 2021
    14 %% Update Count     : 522
     13%% Last Modified On : Wed Feb  3 10:57:33 2021
     14%% Update Count     : 508
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    5757  \pdfstringdefDisableCommands{
    5858  \def\CFA{\CFL}
    59   \def\Celeven{C11\xspace}
    6059  \def\CC{C++\xspace}
    6160  \def\CCeleven{C++11\xspace}
     
    6463  \def\CCtwenty{C++20\xspace}
    6564  \def\Csharp{C\#\xspace}
    66   \def\lstinline{\xspace}% must use {} as delimiters, e.g., \lstinline{...}
     65  \def\lstinline{\xspace} % must use {} as delimiters, e.g., \lstinline{...}
    6766  }{}
    6867}
     
    9897    \vskip 50\p@
    9998  }}
    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}}
     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}}
    102101\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    103102\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}}
     
    252251\newcommand{\LstKeywordStyle}[1]{{\lst@basicstyle{\lst@keywordstyle{#1}}}}
    253252\newcommand{\LstCommentStyle}[1]{{\lst@basicstyle{\lst@commentstyle{#1}}}}
    254 \newcommand{\LstStringStyle}[1]{{\lst@basicstyle{\lst@stringstyle{#1}}}}
    255253
    256254\newlength{\gcolumnposn}                                % temporary hack because lstlisting does not handle tabs correctly
     
    278276xleftmargin=\parindentlnth,                             % indent code to paragraph indentation
    279277extendedchars=true,                                             % allow ASCII characters in the range 128-255
    280 escapechar=\$,                                                  % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
    281 mathescape=false,                                               % LaTeX math escape in CFA code $...$
     278escapechar=§,                                                   % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
     279mathescape=true,                                                % LaTeX math escape in CFA code $...$
    282280keepspaces=true,                                                %
    283281showstringspaces=false,                                 % do not show spaces with cup
     
    297295\lstset{
    298296language=CFA,
    299 moredelim=**[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-^
     297moredelim=**[is][\color{red}]{®}{®},    % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
     298moredelim=**[is][\color{blue}]{ß}{ß},   % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
     299moredelim=**[is][\color{OliveGreen}]{¢}{¢}, % green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
     300moredelim=[is][\lstset{keywords={}}]{¶}{¶}, % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
     301% replace/adjust listing characters that look bad in sanserif
     302add to literate={`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
    304303}% lstset
    305304\lstset{#1}
  • doc/theses/fangren_yu_COOP_F20/Report.tex

    rf4eb705 rd4a4b17  
    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 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 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.
    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, allows a significant amount of code reused, and hence copying, for the intermediate representations, especially in the following two places:
     124The 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:
    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

    rf4eb705 rd4a4b17  
    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 11 0.0000 2 120 90 2925 1325 0\001
    22 4 1 0 50 -1 4 11 0.0000 2 120 90 3075 1325 1\001
    23 4 1 0 50 -1 4 11 0.0000 2 120 90 3225 1325 2\001
    24 4 1 0 50 -1 4 11 0.0000 2 120 90 3375 1325 3\001
    25 4 1 0 50 -1 4 11 0.0000 2 120 90 3525 1325 4\001
     214 1 0 50 -1 4 10 0.0000 2 120 90 2925 1325 0\001
     224 1 0 50 -1 4 10 0.0000 2 120 90 3075 1325 1\001
     234 1 0 50 -1 4 10 0.0000 2 120 90 3225 1325 2\001
     244 1 0 50 -1 4 10 0.0000 2 120 90 3375 1325 3\001
     254 1 0 50 -1 4 10 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 11 0.0000 2 120 90 1350 1650 0\001
    58 4 1 0 50 -1 4 11 0.0000 2 120 90 1500 1650 1\001
    59 4 1 0 50 -1 4 11 0.0000 2 120 90 1650 1650 2\001
    60 4 1 0 50 -1 4 11 0.0000 2 120 90 1800 1650 3\001
    61 4 1 0 50 -1 4 11 0.0000 2 120 90 1950 1650 4\001
    62 4 1 0 50 -1 4 11 0.0000 2 90 90 1200 1325 x\001
    63 4 1 0 50 -1 4 11 0.0000 2 90 90 2400 1325 x\001
     574 1 0 50 -1 4 10 0.0000 2 120 90 1350 1650 0\001
     584 1 0 50 -1 4 10 0.0000 2 120 90 1500 1650 1\001
     594 1 0 50 -1 4 10 0.0000 2 120 90 1650 1650 2\001
     604 1 0 50 -1 4 10 0.0000 2 120 90 1800 1650 3\001
     614 1 0 50 -1 4 10 0.0000 2 120 90 1950 1650 4\001
     624 1 0 50 -1 4 10 0.0000 2 90 90 1200 1325 x\001
     634 1 0 50 -1 4 10 0.0000 2 90 90 2400 1325 x\001
  • doc/user/user.tex

    rf4eb705 rd4a4b17  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Feb  8 21:53:31 2021
    14 %% Update Count     : 4327
     13%% Last Modified On : Mon Oct  5 08:57:29 2020
     14%% Update Count     : 3998
    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 
    5939\newcommand{\CFALatin}{}
    6040% inline code ©...© (copyright symbol) emacs: C-q M-)
     
    6646% math escape $...$ (dollar symbol)
    6747\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
    7069\lstnewenvironment{C++}[1][]                            % use C++ style
    71 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{@}{@},#1}}
     70{\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®},#1}}
    7271{}
    7372
     
    8281\newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
    8382\newcommand{\R}[1]{\Textbf{#1}}
    84 \newcommand{\RC}[1]{\Textbf{\LstBasicStyle{#1}}}
    8583\newcommand{\B}[1]{{\Textbf[blue]{#1}}}
    8684\newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}}
     
    106104\author{
    107105\huge \CFA Team \medskip \\
    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
     106\Large Andrew Beach, Richard Bilson, Peter A. Buhr, Thierry Delisle, \smallskip \\
     107\Large Glen Ditchfield, Rodolfo G. Esteves, Aaron Moss, Rob Schluntz
    111108}% author
    112109
     
    147144\section{Introduction}
    148145
    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.
     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.
    150147The syntax of \CFA builds from C and should look immediately familiar to C/\Index*[C++]{\CC{}} programmers.
    151148% Any language feature that is not described here can be assumed to be using the standard \Celeven syntax.
    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.
     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.
    153150Like 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.
    154151The primary new features include polymorphic routines and types, exceptions, concurrency, and modules.
     
    160157instead, a programmer evolves a legacy program into \CFA by incrementally incorporating \CFA features.
    161158As well, new programs can be written in \CFA using a combination of C and \CFA features.
    162 In 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.
    163159
    164160\Index*[C++]{\CC{}}~\cite{c++:v1} had a similar goal 30 years ago, allowing object-oriented programming to be incrementally added to C.
     
    169165For example, the following programs compare the C, \CFA, and \CC I/O mechanisms, where the programs output the same result.
    170166\begin{center}
    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}$
     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}§
    175171
    176172int main( void ) {
    177173        int x = 0, y = 1, z = 2;
    178         @printf( "%d %d %d\n", x, y, z );@
     174        ®printf( "%d %d %d\n", x, y, z );®
    179175}
    180176\end{cfa}
    181177&
    182178\begin{cfa}
    183 #include <fstream>$\indexc{fstream}$
     179#include <fstream>§\indexc{fstream}§
    184180
    185181int main( void ) {
    186182        int x = 0, y = 1, z = 2;
    187         @sout | x | y | z;@$\indexc{sout}$
     183        ®sout | x | y | z;®§\indexc{sout}§
    188184}
    189185\end{cfa}
    190186&
    191187\begin{cfa}
    192 #include <iostream>$\indexc{iostream}$
     188#include <iostream>§\indexc{iostream}§
    193189using namespace std;
    194190int main() {
    195191        int x = 0, y = 1, z = 2;
    196         @cout<<x<<" "<<y<<" "<<z<<endl;@
     192        ®cout<<x<<" "<<y<<" "<<z<<endl;®
    197193}
    198194\end{cfa}
    199195\end{tabular}
    200196\end{center}
    201 While \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}.
     197While 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}).
    202198
    203199
     
    214210\section{Why fix C?}
    215211
    216 The 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.
     212The 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.
    217213This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
    218214Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    219 For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is the only language of choice.
    220 The 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.
     215For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice.
     216The 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.
    221217The top 4 rankings over the past 35 years are:
    222218\begin{center}
    223219\setlength{\tabcolsep}{10pt}
    224220\begin{tabular}{@{}rcccccccc@{}}
    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} \\
    227 Java    & 2             & 1             & 1             & 2             & 3             & 28    & -             & -             \\
    228 Python  & 3             & 5             & 6             & 7             & 23    & 13    & -             & -             \\
    229 \CC             & 4             & 3             & 3             & 3             & 2             & 2             & 2             & 8             \\
     221                & 2020  & 2015  & 2010  & 2005  & 2000  & 1995  & 1990  & 1985  \\ \hline
     222Java    & 1             & 2             & 1             & 2             & 3             & -             & -             & -             \\
     223\R{C}   & \R{2} & \R{1} & \R{2} & \R{1} & \R{1} & \R{2} & \R{1} & \R{1} \\
     224Python  & 3             & 7             & 6             & 6             & 22    & 21    & -             & -             \\
     225\CC             & 4             & 4             & 4             & 3             & 2             & 1             & 2             & 12    \\
    230226\end{tabular}
    231227\end{center}
     
    236232As stated, the goal of the \CFA project is to engineer modern language-features into C in an evolutionary rather than revolutionary way.
    237233\CC~\cite{C++14,C++} is an example of a similar project;
    238 however, it largely extended the C language, and did not address many of C's existing problems.\footnote{%
     234however, it largely extended the C language, and did not address most of C's existing problems.\footnote{%
    239235Two 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.}
    240236\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.
     
    245241
    246242The 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.
    247 To achieve these goals required a significant engineering exercise, \ie ``thinking \emph{inside} the C box''.
    248 Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern language.
     243To achieve these goals required a significant engineering exercise, where we had to ``think inside the existing C box''.
     244Without these significant extension to C, it is unable to cope with the needs of modern programming problems and programmers;
     245as a result, it will fade into disuse.
     246Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern programming language.
    249247While \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.
    250248While 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.
     
    253251\section{History}
    254252
    255 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 \see{\cite{Werther96} for similar work in \Index*[C++]{\CC{}}}.
     253The \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{}}.)
    256255The first \CFA implementation of these extensions was by \Index*{Rodolfo Esteves}\index{Esteves, Rodolfo}~\cite{Esteves04}.
    257256
    258257The 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):
    259258\begin{cfa}
    260 @forall( otype T )@ T identity( T val ) { return val; }
    261 int forty_two = identity( 42 ); $\C{// T is bound to int, forty\_two == 42}$
     259®forall( otype T )® T identity( T val ) { return val; }
     260int forty_two = identity( 42 ); §\C{// T is bound to int, forty\_two == 42}§
    262261\end{cfa}
    263262% extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions.
    264263\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}.
    265264However, at that time, there was little interesting in extending C, so work did not continue.
    266 As 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.
     265As 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.
    267266
    268267
     
    274273This feature allows \CFA programmers to take advantage of the existing panoply of C libraries to access thousands of external software features.
    275274Language developers often state that adequate \Index{library support} takes more work than designing and implementing the language itself.
    276 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 zero or very low cost.
     275Fortunately, \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.
    277276Hence, \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.
    278277
     
    287286
    288287double key = 5.0, vals[10] = { /* 10 sorted floating values */ };
    289 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$
     288double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); §\C{// search sorted array}§
    290289\end{cfa}
    291290which can be augmented simply with a polymorphic, type-safe, \CFA-overloaded wrappers:
     
    296295
    297296forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {
    298         T * result = bsearch( key, arr, size ); $\C{// call first version}$
    299         return result ? result - arr : size; } $\C{// pointer subtraction includes sizeof(T)}$
    300 
    301 double * val = bsearch( 5.0, vals, 10 ); $\C{// selection based on return type}$
     297        T * result = bsearch( key, arr, size ); §\C{// call first version}§
     298        return result ? result - arr : size; } §\C{// pointer subtraction includes sizeof(T)}§
     299
     300double * val = bsearch( 5.0, vals, 10 ); §\C{// selection based on return type}§
    302301int posn = bsearch( 5.0, vals, 10 );
    303302\end{cfa}
     
    311310\begin{cfa}
    312311forall( dtype T | sized(T) ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); }
    313 int * ip = malloc(); $\C{// select type and size from left-hand side}$
     312int * ip = malloc(); §\C{// select type and size from left-hand side}§
    314313double * dp = malloc();
    315314struct S {...} * sp = malloc();
     
    320319However, it is necessary to differentiate between C and \CFA code because of name \Index{overload}ing, as for \CC.
    321320For 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©.
    322 Whereas, \CFA wraps each of these routines into one overloaded name ©abs©:
    323 \begin{cfa}
    324 char @abs@( char );
    325 extern "C" { int @abs@( int ); } $\C{// use default C routine for int}$
    326 long int @abs@( long int );
    327 long long int @abs@( long long int );
    328 float @abs@( float );
    329 double @abs@( double );
    330 long double @abs@( long double );
    331 float _Complex @abs@( float _Complex );
    332 double _Complex @abs@( double _Complex );
    333 long double _Complex @abs@( long double _Complex );
    334 \end{cfa}
    335 The 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).
    336 Overloaded names must use \newterm{name mangling}\index{mangling!name} to create unique names that are different from unmangled C names.
    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 The only way around this problem is C's approach of creating unique names for each pairing of operation and type.
    339 
    340 This example illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
     321Whereas, \CFA wraps each of these routines into ones with the overloaded name ©abs©:
     322\begin{cfa}
     323char ®abs®( char );
     324extern "C" { int ®abs®( int ); } §\C{// use default C routine for int}§
     325long int ®abs®( long int );
     326long long int ®abs®( long long int );
     327float ®abs®( float );
     328double ®abs®( double );
     329long double ®abs®( long double );
     330float _Complex ®abs®( float _Complex );
     331double _Complex ®abs®( double _Complex );
     332long double _Complex ®abs®( long double _Complex );
     333\end{cfa}
     334The problem is the name clash between the library routine ©abs© and the \CFA names ©abs©.
     335Hence, names appearing in an ©extern "C"© block have \newterm*{C linkage}.
     336Then 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.
     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.
     338There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and types.
     339
     340This example strongly 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{\CFA Compilation}
     346\section[Compiling a CFA Program]{Compiling a \CFA Program}
    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/$\CFA{}$-options ] [ C/$\CFA{}$ source-files ] [ assembler/loader files ]
    351 \end{cfa}
    352 There 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]
     350cfa§\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}
    356354\item
    357355\Indexc{-std=gnu11}\index{compilation option!-std=gnu11@{©-std=gnu11©}}
     
    361359Use the traditional GNU semantics for inline routines in C11 mode, which allows inline routines in header files.
    362360\end{description}
    363 
    364 \CFA has the following new options:
    365 \begin{description}[topsep=0pt]
     361The following new \CFA options are available:
     362\begin{description}
    366363\item
    367364\Indexc{-CFA}\index{compilation option!-CFA@©-CFA©}
    368 Only 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.
     365Only 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.
    369366The generated code starts with the standard \CFA \Index{prelude}.
    370 
    371 \item
    372 \Indexc{-XCFA}\index{compilation option!-XCFA@©-XCFA©}
    373 Pass next flag as-is to the ©cfa-cpp© translator (see details below).
    374367
    375368\item
    376369\Indexc{-debug}\index{compilation option!-debug@©-debug©}
    377370The program is linked with the debugging version of the runtime system.
    378 The debug version performs runtime checks to aid the debugging phase of a \CFA program, but can substantially slow program execution.
     371The debug version performs runtime checks to help during the debugging phase of a \CFA program, but can substantially slow program execution.
    379372The runtime checks should only be removed after the program is completely debugged.
    380373\textbf{This option is the default.}
     
    406399\item
    407400\Indexc{-no-include-stdhdr}\index{compilation option!-no-include-stdhdr@©-no-include-stdhdr©}
    408 Do not supply ©extern "C"© wrappers for \Celeven standard include files \see{\VRef{s:StandardHeaders}}.
     401Do not supply ©extern "C"© wrappers for \Celeven standard include files (see~\VRef{s:StandardHeaders}).
    409402\textbf{This option is \emph{not} the default.}
    410403\end{comment}
     
    437430\begin{cfa}
    438431#ifndef __CFORALL__
    439 #include <stdio.h>$\indexc{stdio.h}$ $\C{// C header file}$
     432#include <stdio.h>§\indexc{stdio.h}§ §\C{// C header file}§
    440433#else
    441 #include <fstream>$\indexc{fstream}$ $\C{// \CFA header file}$
     434#include <fstream>§\indexc{fstream}§ §\C{// \CFA header file}§
    442435#endif
    443436\end{cfa}
     
    445438
    446439The \CFA translator has multiple steps.
    447 The following flags control how the translator works, the stages run, and printing within a stage.
     440The following flags control how the tranlator works, the stages run, and printing within a stage.
    448441The majority of these flags are used by \CFA developers, but some are occasionally useful to programmers.
    449 Each 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]
    451 cfa $test$.cfa -CFA -XCFA -p # print translated code without printing the standard prelude
    452 cfa $test$.cfa -XCFA -P -XCFA parse -XCFA -n # show program parse without prelude
    453 \end{lstlisting}
    454442\begin{description}[topsep=5pt,itemsep=0pt,parsep=0pt]
    455443\item
    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©
     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
    463447\item
    464448\Indexc{-L}\index{translator option!-L@{©-L©}}, \Indexc{--linemarks}\index{translator option!--linemarks@{©--linemarks©}} \, generate line marks
     
    470454\Indexc{-n}\index{translator option!-n@{©-n©}}, \Indexc{--no-prelude}\index{translator option!--no-prelude@{©--no-prelude©}} \, do not read prelude
    471455\item
    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
     456\Indexc{-p}\index{translator option!-p@{©-p©}}, \Indexc{--prototypes}\index{translator option!--prototypes@{©--prototypes©}} \, generate prototypes for prelude functions
    475457\item
    476458\Indexc{-P}\index{translator option!-P@{©-P©}}, \Indexc{--print}\index{translator option!--print@{©--print©}} \, one of:
    477459\begin{description}[topsep=0pt,itemsep=0pt,parsep=0pt]
    478460\item
     461\Indexc{altexpr}\index{translator option!-P@{©-P©}!©altexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, alternatives for expressions
     462\item
    479463\Indexc{ascodegen}\index{translator option!-P@{©-P©}!©ascodegen©}\index{translator option!--print@{©-print©}!©ascodegen©} \, as codegen rather than AST
    480464\item
     465\Indexc{ast}\index{translator option!-P@{©-P©}!©ast©}\index{translator option!--print@{©-print©}!©ast©} \, AST after parsing
     466\item
     467\Indexc{astdecl}\index{translator option!-P@{©-P©}!©astdecl©}\index{translator option!--print@{©-print©}!©astdecl©} \, AST after declaration validation pass
     468\item
    481469\Indexc{asterr}\index{translator option!-P@{©-P©}!©asterr©}\index{translator option!--print@{©-print©}!©asterr©} \, AST on error
    482470\item
     471\Indexc{astexpr}\index{translator option!-P@{©-P©}!©astexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, AST after expression analysis
     472\item
     473\Indexc{astgen}\index{translator option!-P@{©-P©}!©astgen©}\index{translator option!--print@{©-print©}!©astgen©} \, AST after instantiate generics
     474\item
     475\Indexc{box}\index{translator option!-P@{©-P©}!©box©}\index{translator option!--print@{©-print©}!©box©} \, before box step
     476\item
     477\Indexc{ctordtor}\index{translator option!-P@{©-P©}!©ctordtor©}\index{translator option!--print@{©-print©}!©ctordtor©} \, after ctor/dtor are replaced
     478\item
     479\Indexc{codegen}\index{translator option!-P@{©-P©}!©codegen©}\index{translator option!--print@{©-print©}!©codegen©} \, before code generation
     480\item
    483481\Indexc{declstats}\index{translator option!-P@{©-P©}!©declstats©}\index{translator option!--print@{©-print©}!©declstats©} \, code property statistics
    484482\item
    485483\Indexc{parse}\index{translator option!-P@{©-P©}!©parse©}\index{translator option!--print@{©-print©}!©parse©} \, yacc (parsing) debug information
    486484\item
    487 \Indexc{pretty}\index{translator option!-P@{©-P©}!©pretty©}\index{translator option!--print@{©-print©}!©pretty©} \, prettyprint for ©ascodegen© flag
     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
    488488\item
    489489\Indexc{rproto}\index{translator option!-P@{©-P©}!©rproto©}\index{translator option!--print@{©-print©}!©rproto©} \, resolver-proto instance
     
    491491\Indexc{rsteps}\index{translator option!-P@{©-P©}!©rsteps©}\index{translator option!--print@{©-print©}!©rsteps©} \, resolver steps
    492492\item
     493\Indexc{symevt}\index{translator option!-P@{©-P©}!©symevt©}\index{translator option!--print@{©-print©}!©symevt©} \, symbol table events
     494\item
    493495\Indexc{tree}\index{translator option!-P@{©-P©}!©tree©}\index{translator option!--print@{©-print©}!©tree©} \, parse tree
    494496\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
    499 \Indexc{altexpr}\index{translator option!-P@{©-P©}!©altexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, alternatives for expressions
    500 \item
    501 \Indexc{astdecl}\index{translator option!-P@{©-P©}!©astdecl©}\index{translator option!--print@{©-print©}!©astdecl©} \, AST after declaration validation pass
    502 \item
    503 \Indexc{resolver}\index{translator option!-P@{©-P©}!©resolver©}\index{translator option!--print@{©-print©}!©resolver©} \, before resolver step
    504 \item
    505 \Indexc{astexpr}\index{translator option!-P@{©-P©}!©astexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, AST after expression analysis
    506 \item
    507 \Indexc{ctordtor}\index{translator option!-P@{©-P©}!©ctordtor©}\index{translator option!--print@{©-print©}!©ctordtor©} \, after ctor/dtor are replaced
    508 \item
    509497\Indexc{tuple}\index{translator option!-P@{©-P©}!©tuple©}\index{translator option!--print@{©-print©}!©tuple©} \, after tuple expansion
    510 \item
    511 \Indexc{astgen}\index{translator option!-P@{©-P©}!©astgen©}\index{translator option!--print@{©-print©}!©astgen©} \, AST after instantiate generics
    512 \item
    513 \Indexc{box}\index{translator option!-P@{©-P©}!©box©}\index{translator option!--print@{©-print©}!©box©} \, before box step
    514 \item
    515 \Indexc{codegen}\index{translator option!-P@{©-P©}!©codegen©}\index{translator option!--print@{©-print©}!©codegen©} \, before code generation
    516498\end{description}
    517499\item
    518500\Indexc{--prelude-dir} <directory> \, prelude directory for debug/nodebug
    519501\item
    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©
     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}
    521507\item
    522508\Indexc{-t}\index{translator option!-t@{©-t©}}, \Indexc{--tree}\index{translator option!--tree@{©--tree©}} build in tree
     
    527513\label{s:BackquoteIdentifiers}
    528514
    529 \CFA introduces several new keywords \see{\VRef{s:CFAKeywords}} that can clash with existing C variable-names in legacy code.
     515\CFA introduces several new keywords (see \VRef{s:CFAKeywords}) that can clash with existing C variable-names in legacy code.
    530516Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    531517\begin{cfa}
    532 int @``@otype = 3; $\C{// make keyword an identifier}$
    533 double @``@forall = 3.5;
     518int ®``®otype = 3; §\C{// make keyword an identifier}§
     519double ®``®forall = 3.5;
    534520\end{cfa}
    535521
    536522Existing 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.
    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©.
     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©.
    538524Several common C header-files with keyword clashes are fixed in the standard \CFA header-library, so there is a seamless programming-experience.
    539525
     
    541527\begin{cfa}
    542528// include file uses the CFA keyword "with".
    543 #if ! defined( with )                                                   $\C{// nesting ?}$
    544 #define with @``@with                                                   $\C{// make keyword an identifier}$
     529#if ! defined( with ) §\C{// nesting ?}§
     530#define with ®``®with §\C{// make keyword an identifier}§
    545531#define __CFA_BFD_H__
    546532#endif
    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}$
     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}§
    549535#undef with
    550536#undef __CFA_BFD_H__
     
    558544\section{Constant Underscores}
    559545
    560 Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore} as a separator, \eg:
    561 \begin{cfa}
    562 2@_@147@_@483@_@648; $\C{// decimal constant}$
    563 56@_@ul; $\C{// decimal unsigned long constant}$
    564 0@_@377; $\C{// octal constant}$
    565 0x@_@ff@_@ff; $\C{// hexadecimal constant}$
    566 0x@_@ef3d@_@aa5c; $\C{// hexadecimal constant}$
    567 3.141@_@592@_@654; $\C{// floating constant}$
    568 10@_@e@_@+1@_@00; $\C{// floating constant}$
    569 0x@_@ff@_@ff@_@p@_@3; $\C{// hexadecimal floating}$
    570 0x@_@1.ffff@_@ffff@_@p@_@128@_@l; $\C{// hexadecimal floating long constant}$
    571 L@_@$"\texttt{\textbackslash{x}}$@_@$\texttt{ff}$@_@$\texttt{ee}"$; $\C{// wide character constant}$
     546Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore}, \eg:
     547\begin{cfa}
     5482®_®147®_®483®_®648; §\C{// decimal constant}§
     54956®_®ul; §\C{// decimal unsigned long constant}§
     5500®_®377; §\C{// octal constant}§
     5510x®_®ff®_®ff; §\C{// hexadecimal constant}§
     5520x®_®ef3d®_®aa5c; §\C{// hexadecimal constant}§
     5533.141®_®592®_®654; §\C{// floating constant}§
     55410®_®e®_®+1®_®00; §\C{// floating constant}§
     5550x®_®ff®_®ff®_®p®_®3; §\C{// hexadecimal floating}§
     5560x®_®1.ffff®_®ffff®_®p®_®128®_®l; §\C{// hexadecimal floating long constant}§
     557L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§; §\C{// wide character constant}§
    572558\end{cfa}
    573559The rules for placement of underscores are:
     
    588574It 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).
    589575This 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©.
    591576
    592577
    593578\section{Exponentiation Operator}
    594579
    595 C, \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$.
    597 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©.
     580C, \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$.
     582The 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)©.
    598583
    599584There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
     
    602587Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
    603588\begin{cfa}
    604 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
    605            | (1.0f+2.0fi) @\@ (3.0f+2.0fi);
    606 1 1 256 -64 125 @0@ 3273344365508751233 @0@ @0@ -0.015625 18.3791736799526 0.264715-1.1922i
     589sout | 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);
     5911 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
    607592\end{cfa}
    608593Note, ©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.
    609 Because 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 
     594Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
    611595The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
    612596\begin{cfa}
    613 forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
    614 T ?@\@?( T ep, unsigned int y );
    615 forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
    616 T ?@\@?( T ep, unsigned long int y );
     597forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
     598OT ?®\®?( OT ep, unsigned int y );
     599forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
     600OT ?®\®?( OT ep, unsigned long int y );
    617601\end{cfa}
    618602The user type ©T© must define multiplication, one (©1©), and ©*©.
     
    625609
    626610%\subsection{\texorpdfstring{\protect\lstinline@if@/\protect\lstinline@while@ Statement}{if Statement}}
    627 \subsection{\texorpdfstring{\LstKeywordStyle{if} / \LstKeywordStyle{while} Statement}{if / while Statement}}
    628 
    629 The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.\footnote{
    630 Declarations in the ©do©-©while© condition are not useful because they appear after the loop body.}
    631 \begin{cfa}
    632 if ( @int x = f()@ ) ... $\C{// x != 0}$
    633 if ( @int x = f(), y = g()@ ) ... $\C{// x != 0 \&\& y != 0}$
    634 if ( @int x = f(), y = g(); x < y@ ) ... $\C{// relational expression}$
    635 if ( @struct S { int i; } x = { f() }; x.i < 4@ ) $\C{// relational expression}$
    636 
    637 while ( @int x = f()@ ) ... $\C{// x != 0}$
    638 while ( @int x = f(), y = g()@ ) ... $\C{// x != 0 \&\& y != 0}$
    639 while ( @int x = f(), y = g(); x < y@ ) ... $\C{// relational expression}$
    640 while ( @struct S { int i; } x = { f() }; x.i < 4@ ) ... $\C{// relational expression}$
    641 \end{cfa}
    642 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.
    643 The 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.
     611\subsection{\texorpdfstring{\LstKeywordStyle{if}/\LstKeywordStyle{while} Statement}{if/while Statement}}
     612
     613The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.
     614(Does not make sense for ©do©-©while©.)
     615\begin{cfa}
     616if ( ®int x = f()® ) ... §\C{// x != 0}§
     617if ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
     618if ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
     619if ( ®struct S { int i; } x = { f() }; x.i < 4® ) §\C{// relational expression}§
     620
     621while ( ®int x = f()® ) ... §\C{// x != 0}§
     622while ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
     623while ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
     624while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}§
     625\end{cfa}
     626Unless 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.}
     627The scope of the declaration(s) is local to the @if@ statement but exist within both the ``then'' and ``else'' clauses.
    645628
    646629
    647630%\section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}}
    648631\subsection{\texorpdfstring{\LstKeywordStyle{case} Clause}{case Clause}}
    649 \label{s:caseClause}
    650632
    651633C restricts the ©case© clause of a ©switch© statement to a single value.
     
    658640\begin{cfa}
    659641switch ( i ) {
    660   case @1, 3, 5@:
     642  case ®1, 3, 5®:
    661643        ...
    662   case @2, 4, 6@:
     644  case ®2, 4, 6®:
    663645        ...
    664646}
     
    688670\begin{cfa}
    689671switch ( i ) {
    690   case @1~5:@ $\C{// 1, 2, 3, 4, 5}$
     672  case ®1~5:® §\C{// 1, 2, 3, 4, 5}§
    691673        ...
    692   case @10~15:@ $\C{// 10, 11, 12, 13, 14, 15}$
     674  case ®10~15:® §\C{// 10, 11, 12, 13, 14, 15}§
    693675        ...
    694676}
     
    696678Lists of subranges are also allowed.
    697679\begin{cfa}
    698 case @1~5, 12~21, 35~42@:
     680case ®1~5, 12~21, 35~42®:
    699681\end{cfa}
    700682
     
    740722if ( argc == 3 ) {
    741723        // open output file
    742         @// open input file
    743 @} else if ( argc == 2 ) {
    744         @// open input file (duplicate)
    745 
    746 @} else {
     724        ®// open input file
     725®} else if ( argc == 2 ) {
     726        ®// open input file (duplicate)
     727
     728®} else {
    747729        // usage message
    748730}
     
    751733\end{cquote}
    752734In this example, case 2 is always done if case 3 is done.
    753 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.
     735This 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.
    754736C also uses fall-through to handle multiple case-values resulting in the same action:
    755737\begin{cfa}
    756738switch ( i ) {
    757   @case 1: case 3: case 5:@     // odd values
     739  ®case 1: case 3: case 5:®     // odd values
    758740        // odd action
    759741        break;
    760   @case 2: case 4: case 6:@     // even values
     742  ®case 2: case 4: case 6:®     // even values
    761743        // even action
    762744        break;
    763745}
    764746\end{cfa}
    765 This situation better handled without fall-through by allowing a list of case values \see{\VRef{s:caseClause}}.
    766 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 most programming languages with a ©switch© statement.
     747However, this situation is handled in other languages without fall-through by allowing a list of case values.
     748While 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.
    767749Hence, 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.
    768750
     
    774756        if ( j < k ) {
    775757                ...
    776           @case 1:@             // transfer into "if" statement
     758          ®case 1:®             // transfer into "if" statement
    777759                ...
    778760        } // if
     
    780762        while ( j < 5 ) {
    781763                ...
    782           @case 3:@             // transfer into "while" statement
     764          ®case 3:®             // transfer into "while" statement
    783765                ...
    784766        } // while
    785767} // switch
    786768\end{cfa}
    787 This usage branches into control structures, which is known to cause both comprehension and technical difficulties.
    788 The comprehension problem results from the inability to determine how control reaches a particular point due to the number of branches leading to it.
     769The problem with this usage is branching into control structures, which is known to cause both comprehension and technical difficulties.
     770The comprehension problem occurs from the inability to determine how control reaches a particular point due to the number of branches leading to it.
    789771The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
    790 There are few arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
     772There are no positive arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
    791773Nevertheless, C does have an idiom where this capability is used, known as ``\Index*{Duff's device}''~\cite{Duff83}:
    792774\begin{cfa}
     
    812794\item
    813795It is possible to place the ©default© clause anywhere in the list of labelled clauses for a ©switch© statement, rather than only at the end.
    814 Most programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
     796Virtually all programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
    815797The logic for this semantics is that after checking all the ©case© clauses without success, the ©default© clause is selected;
    816798hence, physically placing the ©default© clause at the end of the ©case© clause list matches with this semantics.
     
    821803\begin{cfa}
    822804switch ( x ) {
    823         @int y = 1;@ $\C{// unreachable initialization}$
    824         @x = 7;@ $\C{// unreachable code without label/branch}$
     805        ®int y = 1;® §\C{// unreachable initialization}§
     806        ®x = 7;® §\C{// unreachable code without label/branch}§
    825807  case 0: ...
    826808        ...
    827         @int z = 0;@ $\C{// unreachable initialization, cannot appear after case}$
     809        ®int z = 0;® §\C{// unreachable initialization, cannot appear after case}§
    828810        z = 2;
    829811  case 1:
    830         @x = z;@ $\C{// without fall through, z is uninitialized}$
     812        ®x = z;® §\C{// without fall through, z is uninitialized}§
    831813}
    832814\end{cfa}
    833815While 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.
    834 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©, where both are problematic.
    835 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.
    836 The key observation is that the ©switch© statement branches into a control structure, \ie there are multiple entry points into its statement body.
     816Furthermore, 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.
     817As 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.
     818The key observation is that the ©switch© statement branches into control structure, \ie there are multiple entry points into its statement body.
    837819\end{enumerate}
    838820
     
    860842Therefore, 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:
    861843\begin{cfa}
    862 @choose@ ( i ) {
     844®choose® ( i ) {
    863845  case 1:  case 2:  case 3:
    864846        ...
    865         @// implicit end of switch (break)
    866   @case 5:
     847        ®// implicit end of switch (break)
     848  ®case 5:
    867849        ...
    868         @fallthru@; $\C{// explicit fall through}$
     850        ®fallthru®; §\C{// explicit fall through}§
    869851  case 7:
    870852        ...
    871         @break@ $\C{// explicit end of switch (redundant)}$
     853        ®break® §\C{// explicit end of switch (redundant)}§
    872854  default:
    873855        j = 3;
    874856}
    875857\end{cfa}
    876 Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses.
     858Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses;
    877859An implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.
    878860An 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.
     
    890872\begin{cfa}
    891873switch ( x ) {
    892         @int i = 0;@ $\C{// allowed only at start}$
     874        ®int i = 0;® §\C{// allowed only at start}§
    893875  case 0:
    894876        ...
    895         @int j = 0;@ $\C{// disallowed}$
     877        ®int j = 0;® §\C{// disallowed}§
    896878  case 1:
    897879        {
    898                 @int k = 0;@ $\C{// allowed at different nesting levels}$
     880                ®int k = 0;® §\C{// allowed at different nesting levels}§
    899881                ...
    900           @case 2:@ $\C{// disallow case in nested statements}$
     882          ®case 2:® §\C{// disallow case in nested statements}§
    901883        }
    902884  ...
     
    915897  case 3:
    916898        if ( ... ) {
    917                 ... @fallthru;@ // goto case 4
     899                ... ®fallthru;® // goto case 4
    918900        } else {
    919901                ...
     
    930912choose ( ... ) {
    931913  case 3:
    932         ... @fallthrough common;@
     914        ... ®fallthrough common;®
    933915  case 4:
    934         ... @fallthrough common;@
    935 
    936   @common:@ // below fallthrough
     916        ... ®fallthrough common;®
     917
     918  ®common:® // below fallthrough
    937919                          // at case-clause level
    938920        ...     // common code for cases 3/4
     
    950932                for ( ... ) {
    951933                        // multi-level transfer
    952                         ... @fallthru common;@
     934                        ... ®fallthru common;®
    953935                }
    954936                ...
    955937        }
    956938        ...
    957   @common:@ // below fallthrough
     939  ®common:® // below fallthrough
    958940                          // at case-clause level
    959941\end{cfa}
     
    966948
    967949\begin{figure}
    968 \begin{tabular}{@{}l@{\hspace{25pt}}|l@{}}
    969 \multicolumn{1}{@{}c@{\hspace{25pt}}|}{loop control} & \multicolumn{1}{c@{}}{output} \\
     950\begin{tabular}{@{}l|l@{}}
     951\multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
    970952\hline
    971 \begin{cfa}
    972 while @()@ { sout | "empty"; break; }
    973 do { sout | "empty"; break; } while @()@;
    974 for @()@ { sout | "empty"; break; }
    975 for ( @0@ ) { sout | "A"; } sout | "zero";
    976 for ( @1@ ) { sout | "A"; }
    977 for ( @10@ ) { sout | "A"; }
    978 for ( @= 10@ ) { sout | "A"; }
    979 for ( @1 ~= 10 ~ 2@ ) { sout | "B"; }
    980 for ( @10 -~= 1 ~ 2@ ) { sout | "C"; }
    981 for ( @0.5 ~ 5.5@ ) { sout | "D"; }
    982 for ( @5.5 -~ 0.5@ ) { sout | "E"; }
    983 for ( @i; 10@ ) { sout | i; }
    984 for ( @i; = 10@ ) { sout | i; }
    985 for ( @i; 1 ~= 10 ~ 2@ ) { sout | i; }
    986 for ( @i; 10 -~= 1 ~ 2@ ) { sout | i; }
    987 for ( @i; 0.5 ~ 5.5@ ) { sout | i; }
    988 for ( @i; 5.5 -~ 0.5@ ) { sout | i; }
    989 for ( @ui; 2u ~= 10u ~ 2u@ ) { sout | ui; }
    990 for ( @ui; 10u -~= 2u ~ 2u@ ) { sout | ui; }
     953\begin{cfa}[xleftmargin=0pt]
     954while ®()® { sout | "empty"; break; }
     955do { sout | "empty"; break; } while ®()®;
     956for ®()® { sout | "empty"; break; }
     957for ( ®0® ) { sout | "A"; } sout | "zero";
     958for ( ®1® ) { sout | "A"; }
     959for ( ®10® ) { sout | "A"; }
     960for ( ®= 10® ) { sout | "A"; }
     961for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
     962for ( ®10 -~= 1 ~ 2® ) { sout | "C"; }
     963for ( ®0.5 ~ 5.5® ) { sout | "D"; }
     964for ( ®5.5 -~ 0.5® ) { sout | "E"; }
     965for ( ®i; 10® ) { sout | i; }
     966for ( ®i; = 10® ) { sout | i; }
     967for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
     968for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; }
     969for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
     970for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
     971for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
     972for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; }
    991973enum { N = 10 };
    992 for ( @N@ ) { sout | "N"; }
    993 for ( @i; N@ ) { sout | i; }
    994 for ( @i; N -~ 0@ ) { sout | i; }
     974for ( ®N® ) { sout | "N"; }
     975for ( ®i; N® ) { sout | i; }
     976for ( ®i; N -~ 0® ) { sout | i; }
    995977const int start = 3, comp = 10, inc = 2;
    996 for ( @i; start ~ comp ~ inc + 1@ ) { sout | i; }
    997 for ( i; 1 ~ $\R{@}$ ) { if ( i > 10 ) break; sout | i; }
    998 for ( i; 10 -~ $\R{@}$ ) { if ( i < 0 ) break; sout | i; }
    999 for ( i; 2 ~ $\R{@}$ ~ 2 ) { if ( i > 10 ) break; sout | i; }
    1000 for ( i; 2.1 ~ $\R{@}$ ~ $\R{@}$ ) { if ( i > 10.5 ) break; sout | i; i += 1.7; }
    1001 for ( i; 10 -~ $\R{@}$ ~ 2 ) { if ( i < 0 ) break; sout | i; }
    1002 for ( i; 12.1 ~ $\R{@}$ ~ $\R{@}$ ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; }
    1003 for ( i; 5 @:@ j; -5 ~ $@$ ) { sout | i | j; }
    1004 for ( i; 5 @:@ j; -5 -~ $@$ ) { sout | i | j; }
    1005 for ( i; 5 @:@ j; -5 ~ $@$ ~ 2 ) { sout | i | j; }
    1006 for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 ) { sout | i | j; }
    1007 for ( i; 5 @:@ j; -5 ~ $@$ ) { sout | i | j; }
    1008 for ( i; 5 @:@ j; -5 -~ $@$ ) { sout | i | j; }
    1009 for ( i; 5 @:@ j; -5 ~ $@$ ~ 2 ) { sout | i | j; }
    1010 for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 ) { sout | i | j; }
    1011 for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 @:@ k; 1.5 ~ $@$ ) { sout | i | j | k; }
    1012 for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 @:@ k; 1.5 ~ $@$ ) { sout | i | j | k; }
    1013 for ( i; 5 @:@ k; 1.5 ~ $@$ @:@ j; -5 -~ $@$ ~ 2 ) { sout | i | j | k; }
     978for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
     979for ( i; 1 ~ ®@® ) { if ( i > 10 ) break; sout | i; }
     980for ( i; 10 -~ ®@® ) { if ( i < 0 ) break; sout | i; }
     981for ( i; 2 ~ ®@® ~ 2 ) { if ( i > 10 ) break; sout | i; }
     982for ( i; 2.1 ~ ®@® ~ ®@® ) { if ( i > 10.5 ) break; sout | i; i += 1.7; }
     983for ( i; 10 -~ ®@® ~ 2 ) { if ( i < 0 ) break; sout | i; }
     984for ( i; 12.1 ~ ®@® ~ ®@® ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; }
     985for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
     986for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
     987for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
     988for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
     989for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
     990for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
     991for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
     992for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
     993for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
     994for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
     995for ( i; 5 ®:® k; 1.5 ~ @ ®:® j; -5 -~ @ ~ 2 ) { sout | i | j | k; }
    1014996\end{cfa}
    1015997&
     
    10741056\subsection{Loop Control}
    10751057
    1076 Looping a fixed number of times, possibly with a loop index, occurs frequently.
    1077 \CFA condenses simply looping to facilitate coding speed and safety.
    1078 The ©for©/©while©/©do-while© loop-control is augmented as follows \see{examples in \VRef[Figure]{f:LoopControlExamples}}:
    1079 \begin{itemize}[itemsep=0pt]
     1058The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
     1059\begin{itemize}
     1060\item
     1061The loop index is polymorphic in the type of the comparison value N (when the start value is implicit) or the start value M.
     1062\item
     1063An empty conditional implies comparison value of ©1© (true).
     1064\item
     1065A comparison N is implicit up-to exclusive range [0,N©®)®©.
     1066\item
     1067A comparison ©=© N is implicit up-to inclusive range [0,N©®]®©.
     1068\item
     1069The up-to range M ©~©\index{~@©~©} N means exclusive range [M,N©®)®©.
     1070\item
     1071The up-to range M ©~=©\index{~=@©~=©} N means inclusive range [M,N©®]®©.
     1072\item
     1073The down-to range M ©-~©\index{-~@©-~©} N means exclusive range [N,M©®)®©.
     1074\item
     1075The down-to range M ©-~=©\index{-~=@©-~=©} N means inclusive range [N,M©®]®©.
    10801076\item
    10811077©0© is the implicit start value;
     
    10871083The down-to range uses operator ©-=© for decrement.
    10881084\item
    1089 The 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}
    1091 for ( i; @5@ )                                  $\C[2.5in]{// typeof(5) i; 5 is comparison value}$
    1092 for ( i; @1.5@~5.5~0.5 )                $\C{// typeof(1.5) i; 1.5 is start value}$
    1093 \end{cfa}
    1094 \item
    1095 An empty conditional implies comparison value of ©1© (true).
    1096 \begin{cfa}
    1097 while ( $\R{/*empty*/}$ )               $\C{// while ( true )}$
    1098 for ( $\R{/*empty*/}$ )                 $\C{// for ( ; true; )}$
    1099 do ... while ( $\R{/*empty*/}$ ) $\C{// do ... while ( true )}$
    1100 \end{cfa}
    1101 \item
    1102 A comparison N is implicit up-to exclusive range [0,N\R{)}.
    1103 \begin{cfa}
    1104 for ( @5@ )                                             $\C{// for ( typeof(5) i; i < 5; i += 1 )}$
    1105 \end{cfa}
    1106 \item
    1107 A comparison ©=© N is implicit up-to inclusive range [0,N\R{]}.
    1108 \begin{cfa}
    1109 for ( @=@5 )                                    $\C{// for ( typeof(5) i; i <= 5; i += 1 )}$
    1110 \end{cfa}
    1111 \item
    1112 The up-to range M ©~©\index{~@©~©} N means exclusive range [M,N\R{)}.
    1113 \begin{cfa}
    1114 for ( 1@~@5 )                                   $\C{// for ( typeof(1) i = 1; i < 5; i += 1 )}$
    1115 \end{cfa}
    1116 \item
    1117 The up-to range M ©~=©\index{~=@©~=©} N means inclusive range [M,N\R{]}.
    1118 \begin{cfa}
    1119 for ( 1@~=@5 )                                  $\C{// for ( typeof(1) i = 1; i <= 5; i += 1 )}$
    1120 \end{cfa}
    1121 \item
    1122 The down-to range M ©-~©\index{-~@©-~©} N means exclusive range [N,M\R{)}.
    1123 \begin{cfa}
    1124 for ( 1@-~@5 )                                  $\C{// for ( typeof(1) i = 5; i > 0; i -= 1 )}$
    1125 \end{cfa}
    1126 \item
    1127 The down-to range M ©-~=©\index{-~=@©-~=©} N means inclusive range [N,M\R{]}.
    1128 \begin{cfa}
    1129 for ( 1@-~=@5 )                                 $\C{// for ( typeof(1) i = 5; i >= 0; i -= 1 )}$
    1130 \end{cfa}
    1131 \item
    11321085©@© means put nothing in this field.
    1133 \begin{cfa}
    1134 for ( 1~$\R{@}$~2 )                             $\C{// for ( typeof(1) i = 1; /*empty*/; i += 2 )}$
    1135 \end{cfa}
    11361086\item
    11371087©:© means start another index.
    1138 \begin{cfa}
    1139 for ( 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}
    11411088\end{itemize}
    11421089
     
    11571104\begin{lrbox}{\myboxA}
    11581105\begin{cfa}[tabsize=3]
    1159 @Compound:@ {
    1160         @Try:@ try {
    1161                 @For:@ for ( ... ) {
    1162                         @While:@ while ( ... ) {
    1163                                 @Do:@ do {
    1164                                         @If:@ if ( ... ) {
    1165                                                 @Switch:@ switch ( ... ) {
     1106®Compound:® {
     1107        ®Try:® try {
     1108                ®For:® for ( ... ) {
     1109                        ®While:® while ( ... ) {
     1110                                ®Do:® do {
     1111                                        ®If:® if ( ... ) {
     1112                                                ®Switch:® switch ( ... ) {
    11661113                                                        case 3:
    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@;
     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®;
    11741121                                                        } // switch
    11751122                                                } else {
    1176                                                         ... @break If@; ...     // terminate if
     1123                                                        ... ®break If®; ...     // terminate if
    11771124                                                } // if
    11781125                                } while ( ... ); // do
    11791126                        } // while
    11801127                } // for
    1181         } @finally@ { // always executed
     1128        } ®finally® { // always executed
    11821129        } // try
    11831130} // compound
     
    11891136{
    11901137
    1191                 @ForC:@ for ( ... ) {
    1192                         @WhileC:@ while ( ... ) {
    1193                                 @DoC:@ do {
     1138                ®ForC:® for ( ... ) {
     1139                        ®WhileC:® while ( ... ) {
     1140                                ®DoC:® do {
    11941141                                        if ( ... ) {
    11951142                                                switch ( ... ) {
    11961143                                                        case 3:
    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:@ ;
     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:® ;
    12051152                                                } else {
    1206                                                         ... @goto If@; ...      // terminate if
    1207                                                 } @If:@;
    1208                                 } while ( ... ); @DoB:@ ;
    1209                         } @WhileB:@ ;
    1210                 } @ForB:@ ;
    1211 
    1212 
    1213 } @Compound:@ ;
     1153                                                        ... ®goto If®; ...      // terminate if
     1154                                                } ®If:®;
     1155                                } while ( ... ); ®DoB:® ;
     1156                        } ®WhileB:® ;
     1157                } ®ForB:® ;
     1158
     1159
     1160} ®Compound:® ;
    12141161\end{cfa}
    12151162\end{lrbox}
    12161163
    1217 \hspace*{-10pt}
    12181164\subfloat[\CFA]{\label{f:CFibonacci}\usebox\myboxA}
    12191165\hspace{2pt}
    12201166\vrule
     1167\hspace{2pt}
    12211168\subfloat[C]{\label{f:CFAFibonacciGen}\usebox\myboxB}
    12221169\caption{Multi-level Exit}
     
    12461193Grouping 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:
    12471194\begin{cfa}
    1248 struct S { $\C{// aggregate}$
    1249         char c; $\C{// fields}$
     1195struct S { §\C{// aggregate}§
     1196        char c; §\C{// fields}§
    12501197        int i;
    12511198        double d;
     
    12561203\begin{cfa}
    12571204void f( S s ) {
    1258         @s.@c; @s.@i; @s.@d; $\C{// access containing fields}$
     1205        ®s.®c; ®s.®i; ®s.®d; §\C{// access containing fields}§
    12591206}
    12601207\end{cfa}
     
    12631210\begin{C++}
    12641211struct S {
    1265         char c; $\C{// fields}$
     1212        char c; §\C{// fields}§
    12661213        int i;
    12671214        double d;
    1268         void f() { $\C{// implicit ``this'' aggregate}$
    1269                 @this->@c; @this->@i; @this->@d; $\C{// access containing fields}$
     1215        void f() { §\C{// implicit ``this'' aggregate}§
     1216                ®this->®c; ®this->®i; ®this->®d; §\C{// access containing fields}§
    12701217        }
    12711218}
     
    12751222\begin{cfa}
    12761223struct T { double m, n; };
    1277 int 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 
    1283 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.
     1224int 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
     1230To 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.
    12841231Hence, the qualified fields become variables with the side-effect that it is easier to optimizing field references in a block.
    12851232\begin{cfa}
    1286 void f( S & this ) @with ( this )@ { $\C{// with statement}$
    1287         c; i; d; $\C{\R{// this.c, this.i, this.d}}$
     1233void f( S & this ) ®with ( this )® { §\C{// with statement}§
     1234        c; i; d; §\C{\color{red}// this.c, this.i, this.d}§
    12881235}
    12891236\end{cfa}
    12901237with the generality of opening multiple aggregate-parameters:
    12911238\begin{cfa}
    1292 void 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}}$
     1239void 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}§
    12951242}
    12961243\end{cfa}
     
    12981245In detail, the ©with© statement has the form:
    12991246\begin{cfa}
    1300 $\emph{with-statement}$:
    1301         'with' '(' $\emph{expression-list}$ ')' $\emph{compound-statement}$
     1247§\emph{with-statement}§:
     1248        'with' '(' §\emph{expression-list}§ ')' §\emph{compound-statement}§
    13021249\end{cfa}
    13031250and may appear as the body of a function or nested within a function body.
     
    13111258The difference between parallel and nesting occurs for fields with the same name and type:
    13121259\begin{cfa}
    1313 struct S { int @i@; int j; double m; } s, w;
    1314 struct T { int @i@; int k; int m; } t, w;
     1260struct S { int ®i®; int j; double m; } s, w;
     1261struct T { int ®i®; int k; int m; } t, w;
    13151262with ( s, t ) {
    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}$
     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}§
    13231270}
    13241271\end{cfa}
     
    13301277There is an interesting problem between parameters and the function-body ©with©, \eg:
    13311278\begin{cfa}
    1332 void ?{}( S & s, int i ) with ( s ) { $\C{// constructor}$
    1333         @s.i = i;@  j = 3;  m = 5.5; $\C{// initialize fields}$
     1279void ?{}( S & s, int i ) with ( s ) { §\C{// constructor}§
     1280        ®s.i = i;®  j = 3;  m = 5.5; §\C{// initialize fields}§
    13341281}
    13351282\end{cfa}
     
    13441291and implicitly opened \emph{after} a function-body open, to give them higher priority:
    13451292\begin{cfa}
    1346 void ?{}( S & s, int @i@ ) with ( s ) @with( $\emph{\R{params}}$ )@ {
    1347         s.i = @i@; j = 3; m = 5.5;
     1293void ?{}( S & s, int ®i® ) with ( s ) ®with( §\emph{\color{red}params}§ )® {
     1294        s.i = ®i®; j = 3; m = 5.5;
    13481295}
    13491296\end{cfa}
    13501297Finally, a cast may be used to disambiguate among overload variables in a ©with© expression:
    13511298\begin{cfa}
    1352 with ( w ) { ... } $\C{// ambiguous, same name and no context}$
    1353 with ( (S)w ) { ... } $\C{// unambiguous, cast}$
    1354 \end{cfa}
    1355 and ©with© expressions may be complex expressions with type reference \see{\VRef{s:References}} to aggregate:
     1299with ( w ) { ... } §\C{// ambiguous, same name and no context}§
     1300with ( (S)w ) { ... } §\C{// unambiguous, cast}§
     1301\end{cfa}
     1302and ©with© expressions may be complex expressions with type reference (see Section~\ref{s:References}) to aggregate:
    13561303% \begin{cfa}
    13571304% struct S { int i, j; } sv;
    1358 % with ( sv ) { $\C{// implicit reference}$
     1305% with ( sv ) { §\C{// implicit reference}§
    13591306%       S & sr = sv;
    1360 %       with ( sr ) { $\C{// explicit reference}$
     1307%       with ( sr ) { §\C{// explicit reference}§
    13611308%               S * sp = &sv;
    1362 %               with ( *sp ) { $\C{// computed reference}$
    1363 %                       i = 3; j = 4; $\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}$
     1309%               with ( *sp ) { §\C{// computed reference}§
     1310%                       i = 3; j = 4; §\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}§
    13641311%               }
    1365 %               i = 2; j = 3; $\C{\color{red}// sr.i, sr.j}$
     1312%               i = 2; j = 3; §\C{\color{red}// sr.i, sr.j}§
    13661313%       }
    1367 %       i = 1; j = 2; $\C{\color{red}// sv.i, sv.j}$
     1314%       i = 1; j = 2; §\C{\color{red}// sv.i, sv.j}§
    13681315% }
    13691316% \end{cfa}
     
    13731320class C {
    13741321        int i, j;
    1375         int mem() { $\C{\R{// implicit "this" parameter}}$
    1376                 i = 1; $\C{\R{// this->i}}$
    1377                 j = 2; $\C{\R{// this->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}§
    13781325        }
    13791326}
     
    13821329\begin{cfa}
    13831330struct S { int i, j; };
    1384 int mem( S & @this@ ) { $\C{// explicit "this" parameter}$
    1385         @this.@i = 1; $\C{// "this" is not elided}$
    1386         @this.@j = 2;
     1331int mem( S & ®this® ) { §\C{// explicit "this" parameter}§
     1332        ®this.®i = 1; §\C{// "this" is not elided}§
     1333        ®this.®j = 2;
    13871334}
    13881335\end{cfa}
    13891336but it is cumbersome having to write ``©this.©'' many times in a member.
    13901337
    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}
    1393 int mem( S & this ) @with( this )@ { $\C{// with clause}$
    1394         i = 1; $\C{\R{// this.i}}$
    1395         j = 2; $\C{\R{// this.j}}$
     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}
     1340int mem( S & this ) ®with( this )® { §\C{// with clause}§
     1341        i = 1; §\C{\color{red}// this.i}§
     1342        j = 2; §\C{\color{red}// this.j}§
    13961343}
    13971344\end{cfa}
     
    13991346\begin{cfa}
    14001347struct T { double m, n; };
    1401 int mem2( S & this1, T & this2 ) @with( this1, this2 )@ {
     1348int mem2( S & this1, T & this2 ) ®with( this1, this2 )® {
    14021349        i = 1; j = 2;
    14031350        m = 1.0; n = 2.0;
     
    14101357        struct S1 { ... } s1;
    14111358        struct S2 { ... } s2;
    1412         @with( s1 )@ { $\C{// with statement}$
     1359        ®with( s1 )® { §\C{// with statement}§
    14131360                // access fields of s1 without qualification
    1414                 @with s2@ { $\C{// nesting}$
     1361                ®with s2® { §\C{// nesting}§
    14151362                        // access fields of s1 and s2 without qualification
    14161363                }
    14171364        }
    1418         @with s1, s2@ {
     1365        ®with s1, s2® {
    14191366                // access unambiguous fields of s1 and s2 without qualification
    14201367        }
     
    14671414Non-local transfer can cause stack unwinding, \ie non-local routine termination, depending on the kind of raise.
    14681415\begin{cfa}
    1469 exception_t E {}; $\C{// exception type}$
     1416exception_t E {}; §\C{// exception type}§
    14701417void f(...) {
    1471         ... throw E{}; ... $\C{// termination}$
    1472         ... throwResume E{}; ... $\C{// resumption}$
     1418        ... throw E{}; ... §\C{// termination}§
     1419        ... throwResume E{}; ... §\C{// resumption}§
    14731420}
    14741421try {
    14751422        f(...);
    1476 } catch( E e ; $boolean-predicate$ ) {          $\C{// termination handler}$
     1423} catch( E e ; §boolean-predicate§ ) {          §\C{// termination handler}§
    14771424        // recover and continue
    1478 } catchResume( E e ; $boolean-predicate$ ) { $\C{// resumption handler}$
     1425} catchResume( E e ; §boolean-predicate§ ) { §\C{// resumption handler}§
    14791426        // repair and return
    14801427} finally {
     
    14831430\end{cfa}
    14841431The kind of raise and handler match: ©throw© with ©catch© and ©throwResume© with ©catchResume©.
    1485 Then the exception type must match along with any additional predicate must be true.
     1432Then the exception type must match along with any additonal predicate must be true.
    14861433The ©catch© and ©catchResume© handlers may appear in any oder.
    14871434However, the ©finally© clause must appear at the end of the ©try© statement.
     
    15361483For example, a routine returning a \Index{pointer} to an array of integers is defined and used in the following way:
    15371484\begin{cfa}
    1538 int @(*@f@())[@5@]@ {...}; $\C{// definition}$
    1539  ... @(*@f@())[@3@]@ += 1; $\C{// usage}$
     1485int ®(*®f®())[®5®]® {...}; §\C{// definition}§
     1486 ... ®(*®f®())[®3®]® += 1; §\C{// usage}§
    15401487\end{cfa}
    15411488Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}).
     
    15521499\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    15531500\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    1554 \begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}]
    1555 #[5] *# @int@ x1;
    1556 #* [5]# @int@ x2;
    1557 #[* [5] int]# f@( int p )@;
     1501\begin{cfa}
     1502ß[5] *ß ®int® x1;
     1503ß* [5]ß ®int® x2;
     1504ß[* [5] int]ß f®( int p )®;
    15581505\end{cfa}
    15591506&
    1560 \begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}]
    1561 @int@ #*# x1 #[5]#;
    1562 @int@ #(*#x2#)[5]#;
    1563 #int (*#f@( int p )@#)[5]#;
     1507\begin{cfa}
     1508®int® ß*ß x1 ß[5]ß;
     1509®int® ß(*ßx2ß)[5]ß;
     1510ßint (*ßf®( int p )®ß)[5]ß;
    15641511\end{cfa}
    15651512\end{tabular}
     
    15731520\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    15741521\begin{cfa}
    1575 @*@ int x, y;
     1522®*® int x, y;
    15761523\end{cfa}
    15771524&
    15781525\begin{cfa}
    1579 int @*@x, @*@y;
     1526int ®*®x, ®*®y;
    15801527\end{cfa}
    15811528\end{tabular}
     
    15861533\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    15871534\begin{cfa}
    1588 @*@ int x;
     1535®*® int x;
    15891536int y;
    15901537\end{cfa}
    15911538&
    15921539\begin{cfa}
    1593 int @*@x, y;
     1540int ®*®x, y;
    15941541
    15951542\end{cfa}
     
    17001647
    17011648\section{Pointer / Reference}
    1702 \label{s:PointerReference}
    17031649
    17041650C provides a \newterm{pointer type};
     
    17271673&
    17281674\begin{cfa}
    1729 int * @const@ x = (int *)100
     1675int * ®const® x = (int *)100
    17301676*x = 3;                 // implicit dereference
    1731 int * @const@ y = (int *)104;
     1677int * ®const® y = (int *)104;
    17321678*y = *x;                        // implicit dereference
    17331679\end{cfa}
     
    17671713\begin{tabular}{@{}l@{\hspace{2em}}l@{}}
    17681714\begin{cfa}
    1769 int x, y, @*@ p1, @*@ p2, @**@ p3;
    1770 p1 = @&@x;     // p1 points to x
     1715int x, y, ®*® p1, ®*® p2, ®**® p3;
     1716p1 = ®&®x;     // p1 points to x
    17711717p2 = p1;     // p2 points to x
    1772 p1 = @&@y;     // p1 points to y
     1718p1 = ®&®y;     // p1 points to y
    17731719p3 = &p2;  // p3 points to p2
    17741720\end{cfa}
     
    17821728For example, \Index*{Algol68}~\cite{Algol68} infers pointer dereferencing to select the best meaning for each pointer usage
    17831729\begin{cfa}
    1784 p2 = p1 + x; $\C{// compiler infers *p2 = *p1 + x;}$
     1730p2 = p1 + x; §\C{// compiler infers *p2 = *p1 + x;}§
    17851731\end{cfa}
    17861732Algol68 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.
     
    17901736In C, objects of pointer type always manipulate the pointer object's address:
    17911737\begin{cfa}
    1792 p1 = p2; $\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}$
    1793 p2 = p1 + x; $\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}$
     1738p1 = p2; §\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}§
     1739p2 = p1 + x; §\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}§
    17941740\end{cfa}
    17951741even though the assignment to ©p2© is likely incorrect, and the programmer probably meant:
    17961742\begin{cfa}
    1797 p1 = p2; $\C{// pointer address assignment}$
    1798 @*@p2 = @*@p1 + x; $\C{// pointed-to value assignment / operation}$
     1743p1 = p2; §\C{// pointer address assignment}§
     1744®*®p2 = ®*®p1 + x; §\C{// pointed-to value assignment / operation}§
    17991745\end{cfa}
    18001746The 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©).
     
    18121758To 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).
    18131759\begin{cfa}
    1814 int 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}$
    1819 r2 = ((r1 + r2) * (r3 - r1)) / (r3 - 15); $\C{// implicit dereferencing}$
     1760int 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}§
     1765r2 = ((r1 + r2) * (r3 - r1)) / (r3 - 15); §\C{// implicit dereferencing}§
    18201766\end{cfa}
    18211767Except for auto-dereferencing by the compiler, this reference example is the same as the previous pointer example.
     
    18231769One 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:
    18241770\begin{cfa}
    1825 @*@r2 = ((@*@r1 + @*@r2) @*@ (@**@r3 - @*@r1)) / (@**@r3 - 15);
     1771®*®r2 = ((®*®r1 + ®*®r2) ®*® (®**®r3 - ®*®r1)) / (®**®r3 - 15);
    18261772\end{cfa}
    18271773When a reference operation appears beside a dereference operation, \eg ©&*©, they cancel out.
     
    18321778For a \CFA reference type, the cancellation on the left-hand side of assignment leaves the reference as an address (\Index{lvalue}):
    18331779\begin{cfa}
    1834 (&@*@)r1 = &x; $\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}$
     1780(&®*®)r1 = &x; §\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}§
    18351781\end{cfa}
    18361782Similarly, the address of a reference can be obtained for assignment or computation (\Index{rvalue}):
    18371783\begin{cfa}
    1838 (&(&@*@)@*@)r3 = &(&@*@)r2; $\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}$
     1784(&(&®*®)®*®)r3 = &(&®*®)r2; §\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}§
    18391785\end{cfa}
    18401786Cancellation\index{cancellation!pointer/reference}\index{pointer!cancellation} works to arbitrary depth.
     
    18441790int x, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    18451791                 &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    1846 ***p3 = 3; $\C{// change x}$
    1847 r3 = 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}$
     1792***p3 = 3; §\C{// change x}§
     1793r3 = 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}§
    18531799\end{cfa}
    18541800Furthermore, both types are equally performant, as the same amount of dereferencing occurs for both types.
     
    18571803As for a pointer type, a reference type may have qualifiers:
    18581804\begin{cfa}
    1859 const int cx = 5; $\C{// cannot change cx;}$
    1860 const int & cr = cx; $\C{// cannot change what cr points to}$
    1861 @&@cr = &cx; $\C{// can change cr}$
    1862 cr = 7; $\C{// error, cannot change cx}$
    1863 int & const rc = x; $\C{// must be initialized}$
    1864 @&@rc = &x; $\C{// error, cannot change rc}$
    1865 const int & const crc = cx; $\C{// must be initialized}$
    1866 crc = 7; $\C{// error, cannot change cx}$
    1867 @&@crc = &cx; $\C{// error, cannot change crc}$
     1805const int cx = 5; §\C{// cannot change cx;}§
     1806const int & cr = cx; §\C{// cannot change what cr points to}§
     1807®&®cr = &cx; §\C{// can change cr}§
     1808cr = 7; §\C{// error, cannot change cx}§
     1809int & const rc = x; §\C{// must be initialized}§
     1810®&®rc = &x; §\C{// error, cannot change rc}§
     1811const int & const crc = cx; §\C{// must be initialized}§
     1812crc = 7; §\C{// error, cannot change cx}§
     1813®&®crc = &cx; §\C{// error, cannot change crc}§
    18681814\end{cfa}
    18691815Hence, 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}:
    18701816\begin{cfa}
    1871 int & const cr = *0; $\C{// where 0 is the int * zero}$
     1817int & const cr = *0; §\C{// where 0 is the int * zero}§
    18721818\end{cfa}
    18731819Note, constant reference-types do not prevent \Index{addressing errors} because of explicit storage-management:
     
    18761822cr = 5;
    18771823free( &cr );
    1878 cr = 7; $\C{// unsound pointer dereference}$
     1824cr = 7; §\C{// unsound pointer dereference}§
    18791825\end{cfa}
    18801826
    18811827The position of the ©const© qualifier \emph{after} the pointer/reference qualifier causes confuse for C programmers.
    18821828The ©const© qualifier cannot be moved before the pointer/reference qualifier for C style-declarations;
    1883 \CFA-style declarations \see{\VRef{s:AlternativeDeclarations}} attempt to address this issue:
     1829\CFA-style declarations (see \VRef{s:AlternativeDeclarations}) attempt to address this issue:
    18841830\begin{cquote}
    18851831\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    18861832\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    18871833\begin{cfa}
    1888 @const@ * @const@ * const int ccp;
    1889 @const@ & @const@ & const int ccr;
     1834®const® * ®const® * const int ccp;
     1835®const® & ®const® & const int ccr;
    18901836\end{cfa}
    18911837&
    18921838\begin{cfa}
    1893 const int * @const@ * @const@ ccp;
     1839const int * ®const® * ®const® ccp;
    18941840
    18951841\end{cfa}
     
    19001846Finally, like pointers, references are usable and composable with other type operators and generators.
    19011847\begin{cfa}
    1902 int w, x, y, z, & ar[3] = { x, y, z }; $\C{// initialize array of references}$
    1903 &ar[1] = &w; $\C{// change reference array element}$
    1904 typeof( ar[1] ) p; $\C{// (gcc) is int, \ie the type of referenced object}$
    1905 typeof( &ar[1] ) q; $\C{// (gcc) is int \&, \ie the type of reference}$
    1906 sizeof( ar[1] ) == sizeof( int ); $\C{// is true, \ie the size of referenced object}$
    1907 sizeof( &ar[1] ) == sizeof( int *) $\C{// is true, \ie the size of a reference}$
     1848int w, x, y, z, & ar[3] = { x, y, z }; §\C{// initialize array of references}§
     1849&ar[1] = &w; §\C{// change reference array element}§
     1850typeof( ar[1] ) p; §\C{// (gcc) is int, \ie the type of referenced object}§
     1851typeof( &ar[1] ) q; §\C{// (gcc) is int \&, \ie the type of reference}§
     1852sizeof( ar[1] ) == sizeof( int ); §\C{// is true, \ie the size of referenced object}§
     1853sizeof( &ar[1] ) == sizeof( int *) §\C{// is true, \ie the size of a reference}§
    19081854\end{cfa}
    19091855
    19101856In 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}.
    19111857Also, \CC does not allow \Index{array}s\index{array!reference} of reference\footnote{
    1912 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 referent object.}
     1858The 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.}
    19131859\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.
    19141860
     
    19221868Therefore, for pointer/reference initialization, the initializing value must be an address not a value.
    19231869\begin{cfa}
    1924 int * p = &x; $\C{// assign address of x}$
    1925 @int * p = x;@ $\C{// assign value of x}$
    1926 int & r = x; $\C{// must have address of x}$
     1870int * p = &x; §\C{// assign address of x}§
     1871®int * p = x;® §\C{// assign value of x}§
     1872int & r = x; §\C{// must have address of x}§
    19271873\end{cfa}
    19281874Like 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).
     
    19331879Similarly, 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.
    19341880\begin{cfa}
    1935 int & f( int & r ); $\C{// reference parameter and return}$
    1936 z = f( x ) + f( y ); $\C{// reference operator added, temporaries needed for call results}$
     1881int & f( int & r ); §\C{// reference parameter and return}§
     1882z = f( x ) + f( y ); §\C{// reference operator added, temporaries needed for call results}§
    19371883\end{cfa}
    19381884Within routine ©f©, it is possible to change the argument by changing the corresponding parameter, and parameter ©r© can be locally reassigned within ©f©.
     
    19471893When a pointer/reference parameter has a ©const© value (immutable), it is possible to pass literals and expressions.
    19481894\begin{cfa}
    1949 void f( @const@ int & cr );
    1950 void g( @const@ int * cp );
    1951 f( 3 );                   g( @&@3 );
    1952 f( x + y );             g( @&@(x + y) );
     1895void f( ®const® int & cr );
     1896void g( ®const® int * cp );
     1897f( 3 );                   g( ®&®3 );
     1898f( x + y );             g( ®&®(x + y) );
    19531899\end{cfa}
    19541900Here, 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.
     
    19611907void f( int & r );
    19621908void g( int * p );
    1963 f( 3 );                   g( @&@3 ); $\C{// compiler implicit generates temporaries}$
    1964 f( x + y );             g( @&@(x + y) ); $\C{// compiler implicit generates temporaries}$
     1909f( 3 );                   g( ®&®3 ); §\C{// compiler implicit generates temporaries}§
     1910f( x + y );             g( ®&®(x + y) ); §\C{// compiler implicit generates temporaries}§
    19651911\end{cfa}
    19661912Essentially, there is an implicit \Index{rvalue} to \Index{lvalue} conversion in this case.\footnote{
     
    19731919\begin{cfa}
    19741920void f( int i );
    1975 void (* fp)( int ); $\C{// routine pointer}$
    1976 fp = f; $\C{// reference initialization}$
    1977 fp = &f; $\C{// pointer initialization}$
    1978 fp = *f; $\C{// reference initialization}$
    1979 fp(3); $\C{// reference invocation}$
    1980 (*fp)(3); $\C{// pointer invocation}$
     1921void (* fp)( int ); §\C{// routine pointer}§
     1922fp = f; §\C{// reference initialization}§
     1923fp = &f; §\C{// pointer initialization}§
     1924fp = *f; §\C{// reference initialization}§
     1925fp(3); §\C{// reference invocation}§
     1926(*fp)(3); §\C{// pointer invocation}§
    19811927\end{cfa}
    19821928While 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.
    19831929Instead, a routine object should be referenced by a ©const© reference:
    19841930\begin{cfa}
    1985 @const@ void (@&@ fr)( int ) = f; $\C{// routine reference}$
    1986 fr = ... $\C{// error, cannot change code}$
    1987 &fr = ...; $\C{// changing routine reference}$
    1988 fr( 3 ); $\C{// reference call to f}$
    1989 (*fr)(3); $\C{// error, incorrect type}$
     1931®const® void (®&® fr)( int ) = f; §\C{// routine reference}§
     1932fr = ... §\C{// error, cannot change code}§
     1933&fr = ...; §\C{// changing routine reference}§
     1934fr( 3 ); §\C{// reference call to f}§
     1935(*fr)(3); §\C{// error, incorrect type}§
    19901936\end{cfa}
    19911937because the value of the routine object is a routine literal, \ie the routine code is normally immutable during execution.\footnote{
     
    20001946\begin{itemize}
    20011947\item
    2002 if ©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
    2005 if ©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).
     1948if ©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
     1951if ©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).
    20061952\end{itemize}
    20071953The following example shows the first rule applied to different \Index{rvalue} contexts:
     
    20091955int x, * px, ** ppx, *** pppx, **** ppppx;
    20101956int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    2011 x = rrrx; $\C[2.0in]{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}$
    2012 px = &rrrx; $\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (\&x)}$
    2013 ppx = &&rrrx; $\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (\&rx)}$
    2014 pppx = &&&rrrx; $\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (\&rrx)}$
    2015 ppppx = &&&&rrrx; $\C{// starting from \&\&\&rrrx, \&\&\&\&rrrx is an rvalue with type int **** (\&rrrx)}$
     1957x = rrrx; §\C[2.0in]{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}§
     1958px = &rrrx; §\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (\&x)}§
     1959ppx = &&rrrx; §\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (\&rx)}§
     1960pppx = &&&rrrx; §\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (\&rrx)}§
     1961ppppx = &&&&rrrx; §\C{// starting from \&\&\&rrrx, \&\&\&\&rrrx is an rvalue with type int **** (\&rrrx)}§
    20161962\end{cfa}
    20171963The following example shows the second rule applied to different \Index{lvalue} contexts:
     
    20191965int x, * px, ** ppx, *** pppx;
    20201966int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    2021 rrrx = 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$
     1967rrrx = 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§
    20251971\end{cfa}
    20261972
     
    20351981\begin{cfa}
    20361982int x;
    2037 x + 1; $\C[2.0in]{// lvalue variable (int) converts to rvalue for expression}$
     1983x + 1; §\C[2.0in]{// lvalue variable (int) converts to rvalue for expression}§
    20381984\end{cfa}
    20391985An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped.
     
    20451991\begin{cfa}
    20461992int x, &r = x, f( int p );
    2047 x = @r@ + f( @r@ ); $\C{// lvalue reference converts to rvalue}$
     1993x = ®r® + f( ®r® ); §\C{// lvalue reference converts to rvalue}§
    20481994\end{cfa}
    20491995An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped.
     
    20521998lvalue to reference conversion: \lstinline[deletekeywords=lvalue]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
    20531999\begin{cfa}
    2054 int x, &r = @x@, f( int & p ); $\C{// lvalue variable (int) convert to reference (int \&)}$
    2055 f( @x@ ); $\C{// lvalue variable (int) convert to reference (int \&)}$
     2000int x, &r = ®x®, f( int & p ); §\C{// lvalue variable (int) convert to reference (int \&)}§
     2001f( ®x® ); §\C{// lvalue variable (int) convert to reference (int \&)}§
    20562002\end{cfa}
    20572003Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.
     
    20632009\begin{cfa}
    20642010int x, & f( int & p );
    2065 f( @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$
     2011f( ®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§
    20672013\end{cfa}
    20682014In both case, modifications to the temporary are inaccessible (\Index{warning}).
     
    22362182The point of the new syntax is to allow returning multiple values from a routine~\cite{Galletly96,CLU}, \eg:
    22372183\begin{cfa}
    2238 @[ int o1, int o2, char o3 ]@ f( int i1, char i2, char i3 ) {
    2239         $\emph{routine body}$
     2184®[ int o1, int o2, char o3 ]® f( int i1, char i2, char i3 ) {
     2185        §\emph{routine body}§
    22402186}
    22412187\end{cfa}
     
    22482194Declaration qualifiers can only appear at the start of a routine definition, \eg:
    22492195\begin{cfa}
    2250 @extern@ [ int x ] g( int y ) {$\,$}
     2196®extern® [ int x ] g( int y ) {§\,§}
    22512197\end{cfa}
    22522198Lastly, if there are no output parameters or input parameters, the brackets and/or parentheses must still be specified;
    22532199in 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:
    22542200\begin{cfa}
    2255 [$\,$] g(); $\C{// no input or output parameters}$
    2256 [ void ] g( void ); $\C{// no input or output parameters}$
     2201[§\,§] g(); §\C{// no input or output parameters}§
     2202[ void ] g( void ); §\C{// no input or output parameters}§
    22572203\end{cfa}
    22582204
     
    22722218\begin{cfa}
    22732219typedef int foo;
    2274 int f( int (* foo) ); $\C{// foo is redefined as a parameter name}$
     2220int f( int (* foo) ); §\C{// foo is redefined as a parameter name}§
    22752221\end{cfa}
    22762222The 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.
     
    22802226C-style declarations can be used to declare parameters for \CFA style routine definitions, \eg:
    22812227\begin{cfa}
    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}$
     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}§
    22842230\end{cfa}
    22852231The 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:
    22862232\begin{cfa}
    22872233#define ptoa( n, d ) int (*n)[ d ]
    2288 int 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 ] )}$
     2234int 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 ] )}§
    22902236\end{cfa}
    22912237Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    23062252\begin{minipage}{\linewidth}
    23072253\begin{cfa}
    2308 @[ int x, int y ]@ f() {
     2254®[ int x, int y ]® f() {
    23092255        int z;
    23102256        ... x = 0; ... y = z; ...
    2311         @return;@ $\C{// implicitly return x, y}$
     2257        ®return;® §\C{// implicitly return x, y}§
    23122258}
    23132259\end{cfa}
     
    23192265[ int x, int y ] f() {
    23202266        ...
    2321 } $\C{// implicitly return x, y}$
     2267} §\C{// implicitly return x, y}§
    23222268\end{cfa}
    23232269In this case, the current values of ©x© and ©y© are returned to the calling routine just as if a ©return© had been encountered.
     
    23282274[ int x, int y ] f( int, x, int y ) {
    23292275        ...
    2330 } $\C{// implicitly return x, y}$
     2276} §\C{// implicitly return x, y}§
    23312277\end{cfa}
    23322278This notation allows the compiler to eliminate temporary variables in nested routine calls.
    23332279\begin{cfa}
    2334 [ int x, int y ] f( int, x, int y ); $\C{// prototype declaration}$
     2280[ int x, int y ] f( int, x, int y ); §\C{// prototype declaration}§
    23352281int a, b;
    23362282[a, b] = f( f( f( a, b ) ) );
     
    23462292as well, parameter names are optional, \eg:
    23472293\begin{cfa}
    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}$
     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}§
    23522298\end{cfa}
    23532299This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
    2354 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:
     2300Like 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:
    23552301\begin{cfa}
    23562302C :             const double bar1(), bar2( int ), bar3( double );
    2357 $\CFA$: [const double] foo(), foo( int ), foo( double ) { return 3.0; }
     2303§\CFA§: [const double] foo(), foo( int ), foo( double ) { return 3.0; }
    23582304\end{cfa}
    23592305\CFA allows the last routine in the list to define its body.
     
    23702316The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg:
    23712317\begin{cfa}
    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$
     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}§
    23762322\end{cfa}
    23772323While parameter names are optional, \emph{a routine name cannot be specified};
    23782324for example, the following is incorrect:
    23792325\begin{cfa}
    2380 * [ int x ] f () fp; $\C{// routine name "f" is not allowed}$
     2326* [ int x ] f () fp; §\C{// routine name "f" is not allowed}§
    23812327\end{cfa}
    23822328
     
    24012347whereas a named (keyword) call may be:
    24022348\begin{cfa}
    2403 p( z : 3, x : 4, y : 7 );  $\C{// rewrite \(\Rightarrow\) p( 4, 7, 3 )}$
     2349p( z : 3, x : 4, y : 7 );  §\C{// rewrite $\Rightarrow$ p( 4, 7, 3 )}§
    24042350\end{cfa}
    24052351Here the order of the arguments is unimportant, and the names of the parameters are used to associate argument values with the corresponding parameters.
     
    24182364For example, the following routine prototypes and definition are all valid.
    24192365\begin{cfa}
    2420 void p( int, int, int ); $\C{// equivalent prototypes}$
     2366void p( int, int, int ); §\C{// equivalent prototypes}§
    24212367void p( int x, int y, int z );
    24222368void p( int y, int x, int z );
    24232369void p( int z, int y, int x );
    2424 void p( int q, int r, int s ) {} $\C{// match with this definition}$
     2370void p( int q, int r, int s ) {} §\C{// match with this definition}§
    24252371\end{cfa}
    24262372Forcing matching parameter names in routine prototypes with corresponding routine definitions is possible, but goes against a strong tradition in C programming.
     
    24342380int f( int x, double y );
    24352381
    2436 f( j : 3, i : 4 ); $\C{// 1st f}$
    2437 f( x : 7, y : 8.1 ); $\C{// 2nd f}$
    2438 f( 4, 5 );  $\C{// ambiguous call}$
     2382f( j : 3, i : 4 ); §\C{// 1st f}§
     2383f( x : 7, y : 8.1 ); §\C{// 2nd f}§
     2384f( 4, 5 );  §\C{// ambiguous call}§
    24392385\end{cfa}
    24402386However, named arguments compound routine resolution in conjunction with conversions:
    24412387\begin{cfa}
    2442 f( i : 3, 5.7 ); $\C{// ambiguous call ?}$
     2388f( i : 3, 5.7 ); §\C{// ambiguous call ?}§
    24432389\end{cfa}
    24442390Depending on the cost associated with named arguments, this call could be resolvable or ambiguous.
     
    24542400the allowable positional calls are:
    24552401\begin{cfa}
    2456 p(); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 3 )}$
    2457 p( 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 2, 3 )}$
    2458 p( 4, 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 4, 3 )}$
    2459 p( 4, 4, 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 4, 4 )}$
     2402p(); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
     2403p( 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     2404p( 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     2405p( 4, 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 4 )}§
    24602406// empty arguments
    2461 p(  , 4, 4 ); $\C{// rewrite \(\Rightarrow\) p( 1, 4, 4 )}$
    2462 p( 4,  , 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 2, 4 )}$
    2463 p( 4, 4,   ); $\C{// rewrite \(\Rightarrow\) p( 4, 4, 3 )}$
    2464 p( 4,  ,   ); $\C{// rewrite \(\Rightarrow\) p( 4, 2, 3 )}$
    2465 p(  , 4,   ); $\C{// rewrite \(\Rightarrow\) p( 1, 4, 3 )}$
    2466 p(  ,  , 4 ); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 4 )}$
    2467 p(  ,  ,   ); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 3 )}$
     2407p(  , 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 4 )}§
     2408p( 4,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 4 )}§
     2409p( 4, 4,   ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     2410p( 4,  ,   ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     2411p(  , 4,   ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 3 )}§
     2412p(  ,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 4 )}§
     2413p(  ,  ,   ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
    24682414\end{cfa}
    24692415Here the missing arguments are inserted from the default values in the parameter list.
     
    24892435Default values may only appear in a prototype versus definition context:
    24902436\begin{cfa}
    2491 void p( int x, int y = 2, int z = 3 ); $\C{// prototype: allowed}$
    2492 void p( int, int = 2, int = 3 ); $\C{// prototype: allowed}$
    2493 void p( int x, int y = 2, int z = 3 ) {} $\C{// definition: not allowed}$
     2437void p( int x, int y = 2, int z = 3 ); §\C{// prototype: allowed}§
     2438void p( int, int = 2, int = 3 ); §\C{// prototype: allowed}§
     2439void p( int x, int y = 2, int z = 3 ) {} §\C{// definition: not allowed}§
    24942440\end{cfa}
    24952441The reason for this restriction is to allow separate compilation.
     
    25062452\begin{cfa}
    25072453p( int x, int y, int z, ... );
    2508 p( 1, 4, 5, 6, z : 3, y : 2 ); $\C{// assume p( /* positional */, ... , /* named */ );}$
    2509 p( 1, z : 3, y : 2, 4, 5, 6 ); $\C{// assume p( /* positional */, /* named */, ... );}$
     2454p( 1, 4, 5, 6, z : 3, y : 2 ); §\C{// assume p( /* positional */, ... , /* named */ );}§
     2455p( 1, z : 3, y : 2, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, ... );}§
    25102456\end{cfa}
    25112457In 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.
     
    25162462\begin{cfa}
    25172463void p( int x, int y = 2, int z = 3... );
    2518 p( 1, 4, 5, 6, z : 3 ); $\C{// assume p( /* positional */, ... , /* named */ );}$
    2519 p( 1, z : 3, 4, 5, 6 ); $\C{// assume p( /* positional */, /* named */, ... );}$
     2464p( 1, 4, 5, 6, z : 3 ); §\C{// assume p( /* positional */, ... , /* named */ );}§
     2465p( 1, z : 3, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, ... );}§
    25202466\end{cfa}
    25212467The first call is an error because arguments 4 and 5 are actually positional not ellipse arguments;
     
    25232469In 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.
    25242470For these reasons, \CFA requires named arguments before ellipse arguments.
    2525 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{\VRef{s:Overloading}}, making much of this discussion moot.
    2526 
    2527 Default arguments and overloading \see{\VRef{s:Overloading}} are complementary.
     2471Finally, 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
     2473Default arguments and overloading (see Section 24) are complementary.
    25282474While in theory default arguments can be simulated with overloading, as in:
    25292475\begin{cquote}
     
    25472493Furthermore, overloading cannot handle accessing default arguments in the middle of a positional list, via a missing argument, such as:
    25482494\begin{cfa}
    2549 p( 1, /* default */, 5 ); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 5 )}$
     2495p( 1, /* default */, 5 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 5 )}§
    25502496\end{cfa}
    25512497
     
    25602506\begin{cfa}
    25612507struct {
    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}$
     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}§
    25682514};
    25692515\end{cfa}
     
    25732519\begin{cfa}
    25742520struct {
    2575         int , , ; $\C{// 3 unnamed fields}$
     2521        int , , ; §\C{// 3 unnamed fields}§
    25762522}
    25772523\end{cfa}
     
    25852531\subsection{Type Nesting}
    25862532
    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.
     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.
    25882534\begin{figure}
    25892535\centering
     
    26412587
    26422588int fred() {
    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;
     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;
    26472593}
    26482594\end{cfa}
     
    26672613const unsigned int size = 5;
    26682614int ia[size];
    2669 ... $\C{// assign values to array ia}$
    2670 qsort( ia, size ); $\C{// sort ascending order using builtin ?<?}$
     2615... §\C{// assign values to array ia}§
     2616qsort( ia, size ); §\C{// sort ascending order using builtin ?<?}§
    26712617{
    2672         @int ?<?( int x, int y ) { return x > y; }@ $\C{// nested routine}$
    2673         qsort( ia, size ); $\C{// sort descending order by local redefinition}$
     2618        ®int ?<?( int x, int y ) { return x > y; }® §\C{// nested routine}§
     2619        qsort( ia, size ); §\C{// sort descending order by local redefinition}§
    26742620}
    26752621\end{cfa}
     
    26792625The following program in undefined in \CFA (and Indexc{gcc})
    26802626\begin{cfa}
    2681 [* [int]( int )] foo() { $\C{// int (* foo())( int )}$
    2682         int @i@ = 7;
     2627[* [int]( int )] foo() { §\C{// int (* foo())( int )}§
     2628        int ®i® = 7;
    26832629        int bar( int p ) {
    2684                 @i@ += 1; $\C{// dependent on local variable}$
    2685                 sout | @i@;
     2630                ®i® += 1; §\C{// dependent on local variable}§
     2631                sout | ®i®;
    26862632        }
    2687         return bar; $\C{// undefined because of local dependence}$
     2633        return bar; §\C{// undefined because of local dependence}§
    26882634}
    26892635int main() {
    2690         * [int]( int ) fp = foo(); $\C{// int (* fp)( int )}$
     2636        * [int]( int ) fp = foo(); §\C{// int (* fp)( int )}§
    26912637        sout | fp( 3 );
    26922638}
     
    27012647In C and \CFA, lists of elements appear in several contexts, such as the parameter list of a routine call.
    27022648\begin{cfa}
    2703 f( @2, x, 3 + i@ ); $\C{// element list}$
     2649f( ®2, x, 3 + i® ); §\C{// element list}§
    27042650\end{cfa}
    27052651A list of elements is called a \newterm{tuple}, and is different from a \Index{comma expression}.
     
    27102656
    27112657In C and most programming languages, functions return at most one value;
    2712 however, many operations have multiple outcomes, some exceptional \see{\VRef{s:ExceptionHandling}}.
     2658however, many operations have multiple outcomes, some exceptional (see~\VRef{s:ExceptionHandling}).
    27132659To emulate functions with multiple return values, \emph{\Index{aggregation}} and/or \emph{\Index{aliasing}} is used.
    27142660
     
    27162662For example, consider C's \Indexc{div} function, which returns the quotient and remainder for a division of an integer value.
    27172663\begin{cfa}
    2718 typedef struct { int quot, rem; } div_t;        $\C[7cm]{// from include stdlib.h}$
     2664typedef struct { int quot, rem; } div_t;        §\C[7cm]{// from include stdlib.h}§
    27192665div_t div( int num, int den );
    2720 div_t qr = div( 13, 5 ); $\C{// return quotient/remainder aggregate}$
    2721 printf( "%d %d\n", qr.quot, qr.rem ); $\C{// print quotient/remainder}$
     2666div_t qr = div( 13, 5 ); §\C{// return quotient/remainder aggregate}§
     2667printf( "%d %d\n", qr.quot, qr.rem ); §\C{// print quotient/remainder}§
    27222668\end{cfa}
    27232669This approach requires a name for the return type and fields, where \Index{naming} is a common programming-language issue.
     
    27292675For example, consider C's \Indexc{modf} function, which returns the integral and fractional part of a floating value.
    27302676\begin{cfa}
    2731 double modf( double x, double * i ); $\C{// from include math.h}$
    2732 double intp, frac = modf( 13.5, &intp ); $\C{// return integral and fractional components}$
    2733 printf( "%g %g\n", intp, frac ); $\C{// print integral/fractional components}$
     2677double modf( double x, double * i ); §\C{// from include math.h}§
     2678double intp, frac = modf( 13.5, &intp ); §\C{// return integral and fractional components}§
     2679printf( "%g %g\n", intp, frac ); §\C{// print integral/fractional components}§
    27342680\end{cfa}
    27352681This approach requires allocating storage for the return values, which complicates the call site with a sequence of variable declarations leading to the call.
     
    27582704When 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.
    27592705\begin{cfa}
    2760 void g( int, int ); $\C{// 1}$
    2761 void g( double, double ); $\C{// 2}$
    2762 g( div( 13, 5 ) ); $\C{// select 1}$
    2763 g( modf( 13.5 ) ); $\C{// select 2}$
     2706void g( int, int ); §\C{// 1}§
     2707void g( double, double ); §\C{// 2}§
     2708g( div( 13, 5 ) ); §\C{// select 1}§
     2709g( modf( 13.5 ) ); §\C{// select 2}§
    27642710\end{cfa}
    27652711In this case, there are two overloaded ©g© routines.
     
    27702716The previous examples can be rewritten passing the multiple returned-values directly to the ©printf© function call.
    27712717\begin{cfa}
    2772 [ int, int ] div( int x, int y ); $\C{// from include stdlib}$
    2773 printf( "%d %d\n", div( 13, 5 ) ); $\C{// print quotient/remainder}$
    2774 
    2775 [ double, double ] modf( double x ); $\C{// from include math}$
    2776 printf( "%g %g\n", modf( 13.5 ) ); $\C{// print integral/fractional components}$
     2718[ int, int ] div( int x, int y ); §\C{// from include stdlib}§
     2719printf( "%d %d\n", div( 13, 5 ) ); §\C{// print quotient/remainder}§
     2720
     2721[ double, double ] modf( double x ); §\C{// from include math}§
     2722printf( "%g %g\n", modf( 13.5 ) ); §\C{// print integral/fractional components}§
    27772723\end{cfa}
    27782724This 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.
     
    27842730\begin{cfa}
    27852731int quot, rem;
    2786 [ quot, rem ] = div( 13, 5 ); $\C{// assign multiple variables}$
    2787 printf( "%d %d\n", quot, rem ); $\C{// print quotient/remainder}\CRT$
     2732[ quot, rem ] = div( 13, 5 ); §\C{// assign multiple variables}§
     2733printf( "%d %d\n", quot, rem ); §\C{// print quotient/remainder}\CRT§
    27882734\end{cfa}
    27892735Here, the multiple return-values are matched in much the same way as passing multiple return-values to multiple parameters in a call.
     
    28142760In \CFA, it is possible to overcome this restriction by declaring a \newterm{tuple variable}.
    28152761\begin{cfa}
    2816 [int, int] @qr@ = div( 13, 5 ); $\C{// initialize tuple variable}$
    2817 printf( "%d %d\n", @qr@ ); $\C{// print quotient/remainder}$
     2762[int, int] ®qr® = div( 13, 5 ); §\C{// initialize tuple variable}§
     2763printf( "%d %d\n", ®qr® ); §\C{// print quotient/remainder}§
    28182764\end{cfa}
    28192765It is now possible to match the multiple return-values to a single variable, in much the same way as \Index{aggregation}.
     
    28212767One way to access the individual components of a tuple variable is with assignment.
    28222768\begin{cfa}
    2823 [ quot, rem ] = qr; $\C{// assign multiple variables}$
     2769[ quot, rem ] = qr; §\C{// assign multiple variables}§
    28242770\end{cfa}
    28252771
     
    28442790[int, double] * p;
    28452791
    2846 int y = x.0; $\C{// access int component of x}$
    2847 y = f().1; $\C{// access int component of f}$
    2848 p->0 = 5; $\C{// access int component of tuple pointed-to by p}$
    2849 g( x.1, x.0 ); $\C{// rearrange x to pass to g}$
    2850 double z = [ x, f() ].0.1; $\C{// access second component of first component of tuple expression}$
     2792int y = x.0; §\C{// access int component of x}§
     2793y = f().1; §\C{// access int component of f}§
     2794p->0 = 5; §\C{// access int component of tuple pointed-to by p}§
     2795g( x.1, x.0 ); §\C{// rearrange x to pass to g}§
     2796double z = [ x, f() ].0.1; §\C{// access second component of first component of tuple expression}§
    28512797\end{cfa}
    28522798Tuple-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.
     
    28552801
    28562802\subsection{Flattening and Structuring}
    2857 \label{s:FlatteningStructuring}
    28582803
    28592804As evident in previous examples, tuples in \CFA do not have a rigid structure.
     
    29162861double y;
    29172862[int, double] z;
    2918 [y, x] = 3.14; $\C{// mass assignment}$
    2919 [x, y] = z;                                                         $\C{// multiple assignment}$
    2920 z = 10;                                                         $\C{// mass assignment}$
    2921 z = [x, y]; $\C{// multiple assignment}$
     2863[y, x] = 3.14; §\C{// mass assignment}§
     2864[x, y] = z;                                                         §\C{// multiple assignment}§
     2865z = 10;                                                         §\C{// mass assignment}§
     2866z = [x, y]; §\C{// multiple assignment}§
    29222867\end{cfa}
    29232868Let $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.
     
    29272872\begin{cfa}
    29282873[ int, int ] x, y, z;
    2929 [ x, y ] = z;                                              $\C{// multiple assignment, invalid 4 != 2}$
     2874[ x, y ] = z;                                              §\C{// multiple assignment, invalid 4 != 2}§
    29302875\end{cfa}
    29312876Multiple assignment assigns $R_i$ to $L_i$ for each $i$.
     
    29632908        double c, d;
    29642909        [ void ] f( [ int, int ] );
    2965         f( [ c, a ] = [ b, d ] = 1.5 ); $\C{// assignments in parameter list}$
     2910        f( [ c, a ] = [ b, d ] = 1.5 ); §\C{// assignments in parameter list}§
    29662911\end{cfa}
    29672912The 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.
     
    29762921\begin{cfa}
    29772922struct S;
    2978 void ?{}(S *); $\C{// (1)}$
    2979 void ?{}(S *, int); $\C{// (2)}$
    2980 void ?{}(S * double); $\C{// (3)}$
    2981 void ?{}(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}$
     2923void ?{}(S *); §\C{// (1)}§
     2924void ?{}(S *, int); §\C{// (2)}§
     2925void ?{}(S * double); §\C{// (3)}§
     2926void ?{}(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}§
    29862931\end{cfa}
    29872932In 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)©.
     
    30242969A member-access tuple may be used anywhere a tuple can be used, \eg:
    30252970\begin{cfa}
    3026 s.[ y, z, x ] = [ 3, 3.2, 'x' ]; $\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}$
    3027 f( s.[ y, z ] ); $\C{// equivalent to f( s.y, s.z )}$
     2971s.[ y, z, x ] = [ 3, 3.2, 'x' ]; §\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}§
     2972f( s.[ y, z ] ); §\C{// equivalent to f( s.y, s.z )}§
    30282973\end{cfa}
    30292974Note, the fields appearing in a record-field tuple may be specified in any order;
     
    30352980void f( double, long );
    30362981
    3037 f( x.[ 0, 3 ] ); $\C{// f( x.0, x.3 )}$
    3038 x.[ 0, 1 ] = x.[ 1, 0 ]; $\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}$
     2982f( x.[ 0, 3 ] ); §\C{// f( x.0, x.3 )}§
     2983x.[ 0, 1 ] = x.[ 1, 0 ]; §\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}§
    30392984[ long, int, long ] y = x.[ 2, 0, 2 ];
    30402985\end{cfa}
     
    30532998\begin{cfa}
    30542999[ int, float, double ] f();
    3055 [ double, float ] x = f().[ 2, 1 ]; $\C{// f() called once}$
     3000[ double, float ] x = f().[ 2, 1 ]; §\C{// f() called once}§
    30563001\end{cfa}
    30573002
     
    30663011That 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.
    30673012\begin{cfa}
    3068 int f(); $\C{// (1)}$
    3069 double f(); $\C{// (2)}$
    3070 
    3071 f(); $\C{// ambiguous - (1),(2) both equally viable}$
    3072 (int)f(); $\C{// choose (2)}$
     3013int f(); §\C{// (1)}§
     3014double f(); §\C{// (2)}§
     3015
     3016f(); §\C{// ambiguous - (1),(2) both equally viable}§
     3017(int)f(); §\C{// choose (2)}§
    30733018\end{cfa}
    30743019Since casting is a fundamental operation in \CFA, casts need to be given a meaningful interpretation in the context of tuples.
     
    30783023void g();
    30793024
    3080 (void)f(); $\C{// valid, ignore results}$
    3081 (int)g(); $\C{// invalid, void cannot be converted to int}$
     3025(void)f(); §\C{// valid, ignore results}§
     3026(int)g(); §\C{// invalid, void cannot be converted to int}§
    30823027
    30833028struct A { int x; };
    3084 (struct A)f(); $\C{// invalid, int cannot be converted to A}$
     3029(struct A)f(); §\C{// invalid, int cannot be converted to A}§
    30853030\end{cfa}
    30863031In C, line 4 is a valid cast, which calls ©f© and discards its result.
     
    30983043        [int, [int, int], int] g();
    30993044
    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}$
     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}§
    31053050\end{cfa}
    31063051
     
    31623107void f([int, int], int, int);
    31633108
    3164 f([0, 0], 0, 0); $\C{// no cost}$
    3165 f(0, 0, 0, 0); $\C{// cost for structuring}$
    3166 f([0, 0,], [0, 0]); $\C{// cost for flattening}$
    3167 f([0, 0, 0], 0); $\C{// cost for flattening and structuring}$
     3109f([0, 0], 0, 0); §\C{// no cost}§
     3110f(0, 0, 0, 0); §\C{// cost for structuring}§
     3111f([0, 0,], [0, 0]); §\C{// cost for flattening}§
     3112f([0, 0, 0], 0); §\C{// cost for flattening and structuring}§
    31683113\end{cfa}
    31693114
     
    32013146The general syntax of a lexical list is:
    32023147\begin{cfa}
    3203 [ $\emph{exprlist}$ ]
     3148[ §\emph{exprlist}§ ]
    32043149\end{cfa}
    32053150where ©$\emph{exprlist}$© is a list of one or more expressions separated by commas.
     
    32133158Tuples 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.
    32143159Note, a tuple is not a record (structure);
    3215 a record denotes a single value with substructure, whereas a tuple is multiple values with no substructure \see{flattening coercion in \VRef{s:FlatteningStructuring}}.
     3160a record denotes a single value with substructure, whereas a tuple is multiple values with no substructure (see flattening coercion in Section 12.1).
    32163161In essence, tuples are largely a compile time phenomenon, having little or no runtime presence.
    32173162
     
    32213166The general syntax of a tuple type is:
    32223167\begin{cfa}
    3223 [ $\emph{typelist}$ ]
     3168[ §\emph{typelist}§ ]
    32243169\end{cfa}
    32253170where ©$\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.
     
    32283173[ unsigned int, char ]
    32293174[ double, double, double ]
    3230 [ * int, int * ] $\C{// mix of CFA and ANSI}$
     3175[ * int, int * ] §\C{// mix of CFA and ANSI}§
    32313176[ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    32323177\end{cfa}
     
    32353180Examples of declarations using tuple types are:
    32363181\begin{cfa}
    3237 [ int, int ] x; $\C{// 2 element tuple, each element of type int}$
    3238 * [ char, char ] y; $\C{// pointer to a 2 element tuple}$
     3182[ int, int ] x; §\C{// 2 element tuple, each element of type int}§
     3183* [ char, char ] y; §\C{// pointer to a 2 element tuple}§
    32393184[ [ int, int ] ] z ([ int, int ]);
    32403185\end{cfa}
     
    32533198[ int, int ] w1;
    32543199[ int, int, int ] w2;
    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}$
     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}§
    32573202f( [ 1, 2, 3 ] );
    32583203f( w1, 3 );
     
    33343279[ int, int, int, int ] w = [ 1, 2, 3, 4 ];
    33353280int x = 5;
    3336 [ x, w ] = [ w, x ]; $\C{// all four tuple coercions}$
     3281[ x, w ] = [ w, x ]; §\C{// all four tuple coercions}§
    33373282\end{cfa}
    33383283Starting on the right-hand tuple in the last assignment statement, w is opened, producing a tuple of four values;
     
    33403285This 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.
    33413286The tuple ©[ 2, 3, 4, 5 ]© is then closed to create a tuple value.
    3342 Finally, ©x© is assigned ©1© and ©w© is assigned the tuple value using \Index{multiple assignment} \see{\VRef{s:TupleAssignment}}.
     3287Finally, ©x© is assigned ©1© and ©w© is assigned the tuple value using multiple assignment (see Section 14).
    33433288\begin{rationale}
    33443289A possible additional language extension is to use the structuring coercion for tuples to initialize a complex record with a tuple.
     
    33513296Mass assignment has the following form:
    33523297\begin{cfa}
    3353 [ $\emph{lvalue}$, ... , $\emph{lvalue}$ ] = $\emph{expr}$;
     3298[ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = §\emph{expr}§;
    33543299\end{cfa}
    33553300\index{lvalue}
     
    33913336Multiple assignment has the following form:
    33923337\begin{cfa}
    3393 [ $\emph{lvalue}$, ... , $\emph{lvalue}$ ] = [ $\emph{expr}$, ... , $\emph{expr}$ ];
     3338[ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = [ §\emph{expr}§, ... , §\emph{expr}§ ];
    33943339\end{cfa}
    33953340\index{lvalue}
     
    34223367both these examples produce indeterminate results:
    34233368\begin{cfa}
    3424 f( 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}$
     3369f( 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}§
    34263371\end{cfa}
    34273372
     
    34323377Cascade assignment has the following form:
    34333378\begin{cfa}
    3434 $\emph{tuple}$ = $\emph{tuple}$ = ... = $\emph{tuple}$;
     3379§\emph{tuple}§ = §\emph{tuple}§ = ... = §\emph{tuple}§;
    34353380\end{cfa}
    34363381and it has the same parallel semantics as for mass and multiple assignment.
     
    34793424\begin{cfa}
    34803425int x = 1, y = 2, z = 3;
    3481 sout | x @|@ y @|@ z;
     3426sout | x ®|® y ®|® z;
    34823427\end{cfa}
    34833428&
    34843429\begin{cfa}
    34853430
    3486 cout << x @<< " "@ << y @<< " "@ << z << endl;
     3431cout << x ®<< " "® << y ®<< " "® << z << endl;
    34873432\end{cfa}
    34883433&
     
    34933438\\
    34943439\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3495 1@ @2@ @3
     34401® ®2® ®3
    34963441\end{cfa}
    34973442&
    34983443\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3499 1@ @2@ @3
     34441® ®2® ®3
    35003445\end{cfa}
    35013446&
    35023447\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3503 1@ @2@ @3
     34481® ®2® ®3
    35043449\end{cfa}
    35053450\end{tabular}
     
    35093454\begin{cfa}
    35103455[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    3511 sout | t1 | t2; $\C{// print tuples}$
     3456sout | t1 | t2; §\C{// print tuples}§
    35123457\end{cfa}
    35133458\begin{cfa}[showspaces=true,aboveskip=0pt]
    3514 1@, @2@, @3 4@, @5@, @6
     34591®, ®2®, ®3 4®, ®5®, ®6
    35153460\end{cfa}
    35163461Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority \emph{overloadable} operator, other than assignment.
     
    35213466&
    35223467\begin{cfa}
    3523 sout | x * 3 | y + 1 | z << 2 | x == y | @(@x | y@)@ | @(@x || y@)@ | @(@x > z ? 1 : 2@)@;
     3468sout | x * 3 | y + 1 | z << 2 | x == y | ®(®x | y®)® | ®(®x || y®)® | ®(®x > z ? 1 : 2®)®;
    35243469\end{cfa}
    35253470\\
     
    35273472&
    35283473\begin{cfa}
    3529 cout << x * 3 << y + 1 << @(@z << 2@)@ << @(@x == y@)@ << @(@x | y@)@ << @(@x || y@)@ << @(@x > z ? 1 : 2@)@ << endl;
     3474cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << ®(®x | y®)® << ®(®x || y®)® << ®(®x > z ? 1 : 2®)® << endl;
    35303475\end{cfa}
    35313476\\
     
    35623507\\
    35633508\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3564 @1@ @2.5@ @A@
     3509®1® ®2.5® ®A®
    35653510
    35663511
     
    35683513&
    35693514\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3570 @1@ @2.5@ @A@
     3515®1® ®2.5® ®A®
    35713516
    35723517
     
    35743519&
    35753520\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3576 @1@
    3577 @2.5@
    3578 @A@
     3521®1®
     3522®2.5®
     3523®A®
    35793524\end{cfa}
    35803525\end{tabular}
     
    36123557
    36133558\item
    3614 A 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}
     3559{\lstset{language=CFA,deletedelim=**[is][]{¢}{¢}}
     3560A 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]
    36163562sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    3617            | 7 | "$\LstStringStyle{\textcent}$ x" | 8 | "$\LstStringStyle{\guillemotright}$ x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
    3618 \end{cfa}
    3619 \begin{cfa}[showspaces=true]
    3620 1@,@ 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
    3624 A 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.
     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]
     35661®,® 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
     3570A 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.
    36253571%$
    3626 \begin{cfa}
    3627 sout | "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;
     3572\begin{cfa}[mathescape=off]
     3573sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
     3574                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
    36293575\end{cfa}
    36303576%$
    3631 \begin{cfa}[showspaces=true]
    3632 x @(@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
     3577\begin{cfa}[mathescape=off,basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
     3578x ®(®1 x ®[®2 x ®{®3 x ®=®4 x ®$®5 x ®£®6 x ®¥®7 x ®¡®8 x ®¿®9 x ®«®10
    36333579\end{cfa}
    36343580%$
    36353581
    36363582\item
    3637 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}
    3638 \begin{cfa}
     3583A 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]
    36393585sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx";
    36403586\end{cfa}
    3641 \begin{cfa}[showspaces=true,showtabs=true]
    3642 x@`@1@`@x$\R{\texttt{'}}$2$\R{\texttt{'}}$x$\R{\texttt{"}}$3$\R{\texttt{"}}$x@:@4@:@x@ @5@ @x@  @6@     @x
     3587\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     3588x®`®1®`®x§\color{red}\texttt{'}§2§\color{red}\texttt{'}§x§\color{red}\texttt{"}§3§\color{red}\texttt{"}§x®:®4®:®x® ®5® ®x®      ®6®     ®x
    36433589\end{cfa}
    36443590
    36453591\item
    36463592If a space is desired before or after one of the special string start/end characters, simply insert a space.
    3647 \begin{cfa}
    3648 sout | "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]
    3651 x (@ @1@ @) x 2@ @, x 3@ @:x:@ @4
     3593\begin{cfa}[belowskip=0pt]
     3594sout | "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]
     3597x (® ®1® ®) x 2® ®, x 3® ®:x:® ®4
    36523598\end{cfa}
    36533599\end{enumerate}
     
    36623608\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.
    36633609The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    3664 \begin{cfa}[escapechar=off,belowskip=0pt]
    3665 sepSet( sout, ", $" ); $\C{// set separator from " " to ", \$"}$
    3666 sout | 1 | 2 | 3 | " \"" | @sep@ | "\"";
     3610\begin{cfa}[mathescape=off,belowskip=0pt]
     3611sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§
     3612sout | 1 | 2 | 3 | " \"" | ®sep® | "\"";
    36673613\end{cfa}
    36683614%$
    36693615\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    3670 1@, $@2@, $@3 @", $"@
     36161®, $®2®, $®3 ®", $"®
    36713617\end{cfa}
    36723618%$
    36733619\begin{cfa}[belowskip=0pt]
    3674 sepSet( sout, " " ); $\C{// reset separator to " "}$
    3675 sout | 1 | 2 | 3 | " \"" | @sepGet( sout )@ | "\"";
     3620sepSet( sout, " " ); §\C{// reset separator to " "}§
     3621sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"";
    36763622\end{cfa}
    36773623\begin{cfa}[showspaces=true,aboveskip=0pt]
    3678 1@ @2@ @3 @" "@
     36241® ®2® ®3 ®" "®
    36793625\end{cfa}
    36803626©sepGet© can be used to store a separator and then restore it:
    36813627\begin{cfa}[belowskip=0pt]
    3682 char store[@sepSize@]; $\C{// sepSize is the maximum separator size}$
    3683 strcpy( store, sepGet( sout ) ); $\C{// copy current separator}$
    3684 sepSet( sout, "_" ); $\C{// change separator to underscore}$
     3628char store[®sepSize®]; §\C{// sepSize is the maximum separator size}§
     3629strcpy( store, sepGet( sout ) ); §\C{// copy current separator}§
     3630sepSet( sout, "_" ); §\C{// change separator to underscore}§
    36853631sout | 1 | 2 | 3;
    36863632\end{cfa}
    36873633\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3688 1@_@2@_@3
     36341®_®2®_®3
    36893635\end{cfa}
    36903636\begin{cfa}[belowskip=0pt]
    3691 sepSet( sout, store ); $\C{// change separator back to original}$
     3637sepSet( sout, store ); §\C{// change separator back to original}§
    36923638sout | 1 | 2 | 3;
    36933639\end{cfa}
    36943640\begin{cfa}[showspaces=true,aboveskip=0pt]
    3695 1@ @2@ @3
     36411® ®2® ®3
    36963642\end{cfa}
    36973643
     
    37003646The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    37013647\begin{cfa}[belowskip=0pt]
    3702 sepSetTuple( sout, " " ); $\C{// set tuple separator from ", " to " "}$
    3703 sout | t1 | t2 | " \"" | @sepTuple@ | "\"";
     3648sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§
     3649sout | t1 | t2 | " \"" | ®sepTuple® | "\"";
    37043650\end{cfa}
    37053651\begin{cfa}[showspaces=true,aboveskip=0pt]
    3706 1 2 3 4 5 6 @" "@
     36521 2 3 4 5 6 ®" "®
    37073653\end{cfa}
    37083654\begin{cfa}[belowskip=0pt]
    3709 sepSetTuple( sout, ", " ); $\C{// reset tuple separator to ", "}$
    3710 sout | t1 | t2 | " \"" | @sepGetTuple( sout )@ | "\"";
     3655sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§
     3656sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"";
    37113657\end{cfa}
    37123658\begin{cfa}[showspaces=true,aboveskip=0pt]
    3713 1, 2, 3 4, 5, 6 @", "@
     36591, 2, 3 4, 5, 6 ®", "®
    37143660\end{cfa}
    37153661As for ©sepGet©, ©sepGetTuple© can be use to store a tuple separator and then restore it.
     
    37183664\Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} toggle printing the separator.
    37193665\begin{cfa}[belowskip=0pt]
    3720 sout | sepDisable | 1 | 2 | 3; $\C{// turn off implicit separator}$
     3666sout | sepDisable | 1 | 2 | 3; §\C{// turn off implicit separator}§
    37213667\end{cfa}
    37223668\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    37243670\end{cfa}
    37253671\begin{cfa}[belowskip=0pt]
    3726 sout | sepEnable | 1 | 2 | 3; $\C{// turn on implicit separator}$
     3672sout | sepEnable | 1 | 2 | 3; §\C{// turn on implicit separator}§
    37273673\end{cfa}
    37283674\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    37333679\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.
    37343680\begin{cfa}[belowskip=0pt]
    3735 sout | 1 | sepOff | 2 | 3; $\C{// turn off implicit separator for the next item}$
     3681sout | 1 | sepOff | 2 | 3; §\C{// turn off implicit separator for the next item}§
    37363682\end{cfa}
    37373683\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    37393685\end{cfa}
    37403686\begin{cfa}[belowskip=0pt]
    3741 sout | sepDisable | 1 | sepOn | 2 | 3; $\C{// turn on implicit separator for the next item}$
     3687sout | sepDisable | 1 | sepOn | 2 | 3; §\C{// turn on implicit separator for the next item}§
    37423688\end{cfa}
    37433689\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    37463692The tuple separator also responses to being turned on and off.
    37473693\begin{cfa}[belowskip=0pt]
    3748 sout | t1 | sepOff | t2; $\C{// turn off implicit separator for the next item}$
     3694sout | t1 | sepOff | t2; §\C{// turn off implicit separator for the next item}§
    37493695\end{cfa}
    37503696\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    37543700use ©sep© to accomplish this functionality.
    37553701\begin{cfa}[belowskip=0pt]
    3756 sout | sepOn | 1 | 2 | 3 | sepOn; $\C{// sepOn does nothing at start/end of line}$
     3702sout | sepOn | 1 | 2 | 3 | sepOn; §\C{// sepOn does nothing at start/end of line}§
    37573703\end{cfa}
    37583704\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    37603706\end{cfa}
    37613707\begin{cfa}[belowskip=0pt]
    3762 sout | sep | 1 | 2 | 3 | sep ; $\C{// use sep to print separator at start/end of line}$
     3708sout | sep | 1 | 2 | 3 | sep ; §\C{// use sep to print separator at start/end of line}§
    37633709\end{cfa}
    37643710\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3765 @ @1 2 3@ @
     3711® ®1 2 3® ®
    37663712\end{cfa}
    37673713\end{enumerate}
     
    37753721\begin{enumerate}[parsep=0pt]
    37763722\item
    3777 \Indexc{nl}\index{manipulator!nl@©nl©} scans characters until the next newline character, \ie ignore the remaining characters in the line.
     3723\Indexc{nl}\index{manipulator!nl@©nl©} scans characters until the next newline character, i.e., ignore the remaining characters in the line.
    37783724\item
    37793725\Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} reads the newline character, when reading single characters.
     
    37833729For example, in:
    37843730\begin{cfa}
    3785 sin | i | @nl@ | j;
    3786 1 @2@
     3731sin | i | ®nl® | j;
     37321 ®2®
    378737333
    37883734\end{cfa}
     
    37943740\Indexc{nl}\index{manipulator!nl@©nl©} inserts a newline.
    37953741\begin{cfa}
    3796 sout | nl; $\C{// only print newline}$
    3797 sout | 2; $\C{// implicit newline}$
    3798 sout | 3 | nl | 4 | nl; $\C{// terminating nl merged with implicit newline}$
    3799 sout | 5 | nl | nl; $\C{// again terminating nl merged with implicit newline}$
    3800 sout | 6; $\C{// implicit newline}$
     3742sout | nl; §\C{// only print newline}§
     3743sout | 2; §\C{// implicit newline}§
     3744sout | 3 | nl | 4 | nl; §\C{// terminating nl merged with implicit newline}§
     3745sout | 5 | nl | nl; §\C{// again terminating nl merged with implicit newline}§
     3746sout | 6; §\C{// implicit newline}§
    38013747
    380237482
     
    382537710b0 0b11011 0b11011 0b11011 0b11011
    38263772sout | bin( -27HH ) | bin( -27H ) | bin( -27 ) | bin( -27L );
    3827 0b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b@(58 1s)@100101
     37730b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b®(58 1s)®100101
    38283774\end{cfa}
    38293775
     
    38643810\begin{cfa}[belowskip=0pt]
    38653811sout | upcase( bin( 27 ) ) | upcase( hex( 27 ) ) | upcase( 27.5e-10 ) | upcase( hex( 27.5 ) );
    3866 0@B@11011 0@X@1@B@ 2.75@E@-09 0@X@1.@B@8@P@+4
     38120®B®11011 0®X®1®B® 2.75®E®-09 0®X®1.®B®8®P®+4
    38673813\end{cfa}
    38683814
     
    38803826\begin{cfa}[belowskip=0pt]
    38813827sout | 0. | nodp( 0. ) | 27.0 | nodp( 27.0 ) | nodp( 27.5 );
    3882 0.0 @0@ 27.0 @27@ 27.5
     38280.0 ®0® 27.0 ®27® 27.5
    38833829\end{cfa}
    38843830
     
    38873833\begin{cfa}[belowskip=0pt]
    38883834sout | sign( 27 ) | sign( -27 ) | sign( 27. ) | sign( -27. ) | sign( 27.5 ) | sign( -27.5 );
    3889 @+@27 -27 @+@27.0 -27.0 @+@27.5 -27.5
     3835®+®27 -27 ®+®27.0 -27.0 ®+®27.5 -27.5
    38903836\end{cfa}
    38913837
     
    39003846\end{cfa}
    39013847\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3902 @  @34 @ @34 34
    3903 @  @4.000000 @ @4.000000 4.000000
    3904 @  @ab @ @ab ab
     3848®  ®34 ® ®34 34
     3849®  ®4.000000 ® ®4.000000 4.000000
     3850®  ®ab ® ®ab ab
    39053851\end{cfa}
    39063852If the value is larger, it is printed without truncation, ignoring the ©minimum©.
     
    39113857\end{cfa}
    39123858\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3913 3456@7@ 345@67@ 34@567@
    3914 3456@.@ 345@6.@ 34@56.@
    3915 abcd@e@ abc@de@ ab@cde@
     38593456®7® 345®67® 34®567®
     38603456®.® 345®6.® 34®56.®
     3861abcd®e® abc®de® ab®cde®
    39163862\end{cfa}
    39173863
     
    39223868\end{cfa}
    39233869\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3924  @0@34     @00@34 @00000000@34
     3870 ®0®34     ®00®34 ®00000000®34
    39253871\end{cfa}
    39263872If the value is larger, it is printed without truncation, ignoring the ©precision©.
     
    39373883\end{cfa}
    39383884\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3939 @    @ @00000000@34
     3885®    ® ®00000000®34
    39403886\end{cfa}
    39413887For floating-point types, ©precision© is the minimum number of digits after the decimal point.
     
    39443890\end{cfa}
    39453891\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3946 27.@500@     27.@5@      28. 27.@50000000@
    3947 \end{cfa}
    3948 For the C-string type, ©precision© is the maximum number of printed characters, so the string is truncated if it exceeds the maximum.
     389227.®500®     27.®5®      28. 27.®50000000®
     3893\end{cfa}
     3894For the C-string type, ©precision© is the maximum number of printed characters, so the string is truncared if it exceeds the maximum.
    39493895\begin{cfa}[belowskip=0pt]
    39503896sout | wd( 6,8, "abcd" ) | wd( 6,8, "abcdefghijk" ) | wd( 6,3, "abcd" );
     
    39623908\end{cfa}
    39633909\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3964 234.567 234.5@7@  234.@6@    23@5@
     3910234.567 234.5®7®  234.®6®    23®5®
    39653911\end{cfa}
    39663912If a value's magnitude is greater than ©significant©, the value is printed in scientific notation with the specified number of significant digits.
     
    39693915\end{cfa}
    39703916\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3971 234567. 2.3457@e+05@ 2.346@e+05@ 2.35@e+05@
     3917234567. 2.3457®e+05® 2.346®e+05® 2.35®e+05®
    39723918\end{cfa}
    39733919If ©significant© is greater than ©minimum©, it defines the number of printed characters.
     
    39853931\end{cfa}
    39863932\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3987 27@  @ 27.000000  27.500000  027  27.500@    @
     393327®  ® 27.000000  27.500000  027  27.500®    ®
    39883934\end{cfa}
    39893935
     
    39923938\begin{cfa}[belowskip=0pt]
    39933939sout | pad0( wd( 4, 27 ) ) | pad0( wd( 4,3, 27 ) ) | pad0( wd( 8,3, 27.5 ) );
    3994 @00@27  @0@27 @00@27.500
     3940®00®27  ®0®27 ®00®27.500
    39953941\end{cfa}
    39963942\end{enumerate}
     
    40884034\end{cfa}
    40894035\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4090 @abc   @
    4091 @abc  @
    4092 @xx@
     4036®abc   ®
     4037®abc  ®
     4038®xx®
    40934039\end{cfa}
    40944040
     
    41014047\end{cfa}
    41024048\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4103 @abcd1233.456E+2@
     4049®abcd1233.456E+2®
    41044050\end{cfa}
    41054051Note, input ©wdi© cannot be overloaded with output ©wd© because both have the same parameters but return different types.
     
    41144060\end{cfa}
    41154061\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4116 @  -75.35e-4@ 25
     4062®  -75.35e-4® 25
    41174063\end{cfa}
    41184064
     
    41264072\end{cfa}
    41274073\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4128 @bca@xyz
     4074®bca®xyz
    41294075\end{cfa}
    41304076
     
    41384084\end{cfa}
    41394085\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4140 @xyz@bca
     4086®xyz®bca
    41414087\end{cfa}
    41424088\end{enumerate}
     
    41554101
    41564102A 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.
    4157 This means that users can define distinct function overloads for the new type \see{\VRef{s:Overloading} for more information}.
     4103This means that users can define distinct function overloads for the new type (see Overloading for more information).
    41584104For example:
    41594105
     
    42614207\CFA supports C initialization of structures, but it also adds constructors for more advanced initialization.
    42624208Additionally, \CFA adds destructors that are called when a variable is deallocated (variable goes out of scope or object is deleted).
    4263 These functions take a reference to the structure as a parameter \see{\VRef{s:PointerReference} for more information}.
     4209These functions take a reference to the structure as a parameter (see References for more information).
    42644210
    42654211\begin{figure}
     
    43124258
    43134259\section{Overloading}
    4314 \label{s:Overloading}
    43154260
    43164261Overloading refers to the capability of a programmer to define and use multiple objects in a program with the same name.
     
    45234468For example, given
    45244469\begin{cfa}
    4525 auto j = @...@
     4470auto j = ®...®
    45264471\end{cfa}
    45274472and the need to write a routine to compute using ©j©
    45284473\begin{cfa}
    4529 void rtn( @...@ parm );
     4474void rtn( ®...® parm );
    45304475rtn( j );
    45314476\end{cfa}
     
    47684713
    47694714coroutine Fibonacci {
    4770         int fn; $\C{// used for communication}$
     4715        int fn; §\C{// used for communication}§
    47714716};
    47724717void ?{}( Fibonacci * this ) {
     
    47744719}
    47754720void main( Fibonacci * this ) {
    4776         int fn1, fn2; $\C{// retained between resumes}$
    4777         this->fn = 0; $\C{// case 0}$
     4721        int fn1, fn2; §\C{// retained between resumes}§
     4722        this->fn = 0; §\C{// case 0}§
    47784723        fn1 = this->fn;
    4779         suspend(); $\C{// return to last resume}$
    4780 
    4781         this->fn = 1; $\C{// case 1}$
     4724        suspend(); §\C{// return to last resume}§
     4725
     4726        this->fn = 1; §\C{// case 1}§
    47824727        fn2 = fn1;
    47834728        fn1 = this->fn;
    4784         suspend(); $\C{// return to last resume}$
    4785 
    4786         for ( ;; ) { $\C{// general case}$
     4729        suspend(); §\C{// return to last resume}§
     4730
     4731        for ( ;; ) { §\C{// general case}§
    47874732                this->fn = fn1 + fn2;
    47884733                fn2 = fn1;
    47894734                fn1 = this->fn;
    4790                 suspend(); $\C{// return to last resume}$
     4735                suspend(); §\C{// return to last resume}§
    47914736        } // for
    47924737}
    47934738int next( Fibonacci * this ) {
    4794         resume( this ); $\C{// transfer to last suspend}$
     4739        resume( this ); §\C{// transfer to last suspend}§
    47954740        return this->fn;
    47964741}
     
    50194964When 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.
    50204965
    5021 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{\VRef{s:Interoperability} for more information}.
     4966In 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).
    50224967
    50234968
     
    63376282In \CFA, there are ambiguous cases with dereference and operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be interpreted as:
    63386283\begin{cfa}
    6339 *?$\R{\textvisiblespace}$*? $\C{// dereference operator, dereference operator}$
    6340 *$\R{\textvisiblespace}$?*? $\C{// dereference, multiplication operator}$
     6284*?§\color{red}\textvisiblespace§*? §\C{// dereference operator, dereference operator}§
     6285*§\color{red}\textvisiblespace§?*? §\C{// dereference, multiplication operator}§
    63416286\end{cfa}
    63426287By default, the first interpretation is selected, which does not yield a meaningful parse.
     
    63476292The ambiguity occurs when the deference operator has no parameters:
    63486293\begin{cfa}
    6349 *?()$\R{\textvisiblespace...}$ ;
    6350 *?()$\R{\textvisiblespace...}$(...) ;
     6294*?()§\color{red}\textvisiblespace...§ ;
     6295*?()§\color{red}\textvisiblespace...§(...) ;
    63516296\end{cfa}
    63526297requiring arbitrary whitespace look-ahead for the routine-call parameter-list to disambiguate.
     
    63566301The remaining cases are with the increment/decrement operators and conditional expression, \eg:
    63576302\begin{cfa}
    6358 i++?$\R{\textvisiblespace...}$(...);
    6359 i?++$\R{\textvisiblespace...}$(...);
     6303i++?§\color{red}\textvisiblespace...§(...);
     6304i?++§\color{red}\textvisiblespace...§(...);
    63606305\end{cfa}
    63616306requiring arbitrary whitespace look-ahead for the operator parameter-list, even though that interpretation is an incorrect expression (juxtaposed identifiers).
    63626307Therefore, it is necessary to disambiguate these cases with a space:
    63636308\begin{cfa}
    6364 i++$\R{\textvisiblespace}$? i : 0;
    6365 i?$\R{\textvisiblespace}$++i : 0;
     6309i++§\color{red}\textvisiblespace§? i : 0;
     6310i?§\color{red}\textvisiblespace§++i : 0;
    63666311\end{cfa}
    63676312
     
    63766321\begin{description}
    63776322\item[Change:] add new keywords \\
    6378 New keywords are added to \CFA \see{\VRef{s:CFAKeywords}}.
     6323New keywords are added to \CFA (see~\VRef{s:CFAKeywords}).
    63796324\item[Rationale:] keywords added to implement new semantics of \CFA.
    63806325\item[Effect on original feature:] change to semantics of well-defined feature. \\
    63816326Any \Celeven programs using these keywords as identifiers are invalid \CFA programs.
    6382 \item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism \see{\VRef{s:BackquoteIdentifiers}}.
     6327\item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}).
    63836328\item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
    63846329\end{description}
     
    63906335\eg:
    63916336\begin{cfa}
    6392 x; $\C{// int x}$
    6393 *y; $\C{// int *y}$
    6394 f( p1, p2 ); $\C{// int f( int p1, int p2 );}$
    6395 g( p1, p2 ) int p1, p2; $\C{// int g( int p1, int p2 );}$
     6337x; §\C{// int x}§
     6338*y; §\C{// int *y}§
     6339f( p1, p2 ); §\C{// int f( int p1, int p2 );}§
     6340g( p1, p2 ) int p1, p2; §\C{// int g( int p1, int p2 );}§
    63966341\end{cfa}
    63976342\CFA continues to support K\&R routine definitions:
    63986343\begin{cfa}
    6399 f( a, b, c ) $\C{// default int return}$
    6400         int a, b; char c $\C{// K\&R parameter declarations}$
     6344f( a, b, c ) §\C{// default int return}§
     6345        int a, b; char c §\C{// K\&R parameter declarations}§
    64016346{
    64026347        ...
     
    64176362int rtn( int i );
    64186363int rtn( char c );
    6419 rtn( 'x' ); $\C{// programmer expects 2nd rtn to be called}$
     6364rtn( 'x' ); §\C{// programmer expects 2nd rtn to be called}§
    64206365\end{cfa}
    64216366\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
     
    64396384\item[Change:] make string literals ©const©:
    64406385\begin{cfa}
    6441 char * p = "abc"; $\C{// valid in C, deprecated in \CFA}$
    6442 char * q = expr ? "abc" : "de"; $\C{// valid in C, invalid in \CFA}$
     6386char * p = "abc"; §\C{// valid in C, deprecated in \CFA}§
     6387char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
    64436388\end{cfa}
    64446389The type of a string literal is changed from ©[] char© to ©const [] char©.
     
    64476392\begin{cfa}
    64486393char * p = "abc";
    6449 p[0] = 'w'; $\C{// segment fault or change constant literal}$
     6394p[0] = 'w'; §\C{// segment fault or change constant literal}§
    64506395\end{cfa}
    64516396The same problem occurs when passing a string literal to a routine that changes its argument.
     
    64596404\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
    64606405\begin{cfa}
    6461 int i; $\C{// forward definition}$
    6462 int *j = @&i@; $\C{// forward reference, valid in C, invalid in \CFA}$
    6463 int i = 0; $\C{// definition}$
     6406int i; §\C{// forward definition}§
     6407int *j = ®&i®; §\C{// forward reference, valid in C, invalid in \CFA}§
     6408int i = 0; §\C{// definition}§
    64646409\end{cfa}
    64656410is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
     
    64676412\begin{cfa}
    64686413struct X { int i; struct X *next; };
    6469 static struct X a; $\C{// forward definition}$
    6470 static struct X b = { 0, @&a@ };$\C{// forward reference, valid in C, invalid in \CFA}$
    6471 static struct X a = { 1, &b }; $\C{// definition}$
     6414static struct X a; §\C{// forward definition}§
     6415static struct X b = { 0, ®&a® };§\C{// forward reference, valid in C, invalid in \CFA}§
     6416static struct X a = { 1, &b }; §\C{// definition}§
    64726417\end{cfa}
    64736418\item[Rationale:] avoids having different initialization rules for builtin types and user-defined types.
     
    64816426\item[Change:] have ©struct© introduce a scope for nested types:
    64826427\begin{cfa}
    6483 enum @Colour@ { R, G, B, Y, C, M };
     6428enum ®Colour® { R, G, B, Y, C, M };
    64846429struct Person {
    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)}$
     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)}§
    64886433        };
    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}$
     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}§
    64926437};
    6493 @Colour@ c = R; $\C{// type/enum defined same level}$
    6494 Person@.Colour@ pc = Person@.@R;$\C{// type/enum defined inside}$
    6495 Person@.@Face pretty; $\C{// type defined inside}\CRT$
     6438®Colour® c = R; §\C{// type/enum defined same level}§
     6439Person®.Colour® pc = Person®.®R;§\C{// type/enum defined inside}§
     6440Person®.®Face pretty; §\C{// type defined inside}\CRT§
    64966441\end{cfa}
    64976442In 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.
     
    65106455\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:
    65116456\begin{cfa}
    6512 struct Y; $\C{// struct Y and struct X are at the same scope}$
     6457struct Y; §\C{// struct Y and struct X are at the same scope}§
    65136458struct X {
    65146459        struct Y { /* ... */ } y;
     
    65256470\begin{cfa}
    65266471void foo() {
    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 *}$
     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 *}§
    65296474}
    65306475\end{cfa}
    65316476\item[Rationale:] increase type safety
    65326477\item[Effect on original feature:] deletion of semantically well-defined feature.
    6533 \item[Difficulty of converting:] requires adding a cast \see{\VRef{s:StorageManagement} for better alternatives}:
     6478\item[Difficulty of converting:] requires adding a cast (see \VRef{s:StorageManagement} for better alternatives):
    65346479\begin{cfa}
    65356480        int * b = (int *)malloc( sizeof(int) );
     
    66416586\end{cquote}
    66426587For the prescribed head-files, \CFA uses header interposition to wraps these includes in an ©extern "C"©;
    6643 hence, names in these include files are not mangled\index{mangling!name} \see{\VRef{s:Interoperability}}.
     6588hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}).
    66446589All other C header files must be explicitly wrapped in ©extern "C"© to prevent name mangling.
    66456590This 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.
     
    67046649Type-safe allocation is provided for all C allocation routines and new \CFA allocation routines, \eg in
    67056650\begin{cfa}
    6706 int * ip = (int *)malloc( sizeof(int) );                $\C{// C}$
    6707 int * ip = malloc();                                                    $\C{// \CFA type-safe version of C malloc}$
    6708 int * ip = alloc();                                                             $\C{// \CFA type-safe uniform alloc}$
     6651int * ip = (int *)malloc( sizeof(int) );                §\C{// C}§
     6652int * ip = malloc();                                                    §\C{// \CFA type-safe version of C malloc}§
     6653int * ip = alloc();                                                             §\C{// \CFA type-safe uniform alloc}§
    67096654\end{cfa}
    67106655the latter two allocations determine the allocation size from the type of ©p© (©int©) and cast the pointer to the allocated storage to ©int *©.
     
    67136658\begin{cfa}
    67146659struct S { int i; } __attribute__(( aligned( 128 ) )); // cache-line alignment
    6715 S * sp = malloc();                                                              $\C{// honour type alignment}$
     6660S * sp = malloc();                                                              §\C{// honour type alignment}§
    67166661\end{cfa}
    67176662the storage allocation is implicitly aligned to 128 rather than the default 16.
     
    67286673\CFA memory management extends allocation to support constructors for initialization of allocated storage, \eg in
    67296674\begin{cfa}
    6730 struct S { int i; };                                                    $\C{// cache-line alignment}$
     6675struct S { int i; };                                                    §\C{// cache-line aglinment}§
    67316676void ?{}( S & s, int i ) { s.i = i; }
    67326677// assume ?|? operator for printing an S
    67336678
    6734 S & sp = *@new@( 3 );                                                   $\C{// call constructor after allocation}$
     6679S & sp = *®new®( 3 );                                                   §\C{// call constructor after allocation}§
    67356680sout | sp.i;
    6736 @delete@( &sp );
    6737 
    6738 S * spa = @anew@( 10, 5 );                                              $\C{// allocate array and initialize each array element}$
     6681®delete®( &sp );
     6682
     6683S * spa = ®anew®( 10, 5 );                                              §\C{// allocate array and initialize each array element}§
    67396684for ( i; 10 ) sout | spa[i] | nonl;
    67406685sout | nl;
    6741 @adelete@( 10, spa );
     6686®adelete®( 10, spa );
    67426687\end{cfa}
    67436688Allocation routines ©new©/©anew© allocate a variable/array and initialize storage using the allocated type's constructor.
     
    67486693extern "C" {
    67496694        // C unsafe allocation
    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
     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
    67576702
    67586703        // C unsafe initialization/copy
    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}$
     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}§
    67616706}
    67626707
     
    67646709
    67656710forall( dtype T | sized(T) ) {
    6766         // $\CFA$ safe equivalents, i.e., implicit size specification
     6711        // §\CFA§ safe equivalents, i.e., implicit size specification
    67676712        T * malloc( void );
    67686713        T * calloc( size_t dim );
     
    67736718        int posix_memalign( T ** ptr, size_t align );
    67746719
    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
     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
    68046749        T * amemset( T dest[], char fill, size_t dim );
    68056750        T * amemcpy( T dest[], const T src[], size_t dim );
    68066751}
    68076752
    6808 // $\CFA$ allocation/deallocation and constructor/destructor, non-array types
    6809 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );$\indexc{new}$
    6810 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );$\indexc{delete}$
     6753// §\CFA§ allocation/deallocation and constructor/destructor, non-array types
     6754forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );§\indexc{new}§
     6755forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );§\indexc{delete}§
    68116756forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } )
    68126757  void delete( T * ptr, Params rest );
    68136758
    6814 // $\CFA$ allocation/deallocation and constructor/destructor, array types
    6815 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );$\indexc{anew}$
    6816 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );$\indexc{adelete}$
     6759// §\CFA§ allocation/deallocation and constructor/destructor, array types
     6760forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
     6761forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
    68176762forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } )
    68186763  void adelete( size_t dim, T arr[], Params rest );
     
    68246769\leavevmode
    68256770\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6826 int ato( const char * ptr );$\indexc{ato}$
     6771int ato( const char * ptr );§\indexc{ato}§
    68276772unsigned int ato( const char * ptr );
    68286773long int ato( const char * ptr );
     
    68566801\leavevmode
    68576802\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6858 forall( otype T | { int ?<?( T, T ); } ) $\C{// location}$
    6859 T * bsearch( T key, const T * arr, size_t dim );$\indexc{bsearch}$
    6860 
    6861 forall( otype T | { int ?<?( T, T ); } ) $\C{// position}$
     6803forall( otype T | { int ?<?( T, T ); } ) §\C{// location}§
     6804T * bsearch( T key, const T * arr, size_t dim );§\indexc{bsearch}§
     6805
     6806forall( otype T | { int ?<?( T, T ); } ) §\C{// position}§
    68626807unsigned int bsearch( T key, const T * arr, size_t dim );
    68636808
    68646809forall( otype T | { int ?<?( T, T ); } )
    6865 void qsort( const T * arr, size_t dim );$\indexc{qsort}$
     6810void qsort( const T * arr, size_t dim );§\indexc{qsort}§
    68666811
    68676812forall( otype E | { int ?<?( E, E ); } ) {
    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}$
     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}§
    68716816        size_t bsearchl( E key, const E * vals, size_t dim );
    6872         E * bsearchu( E key, const E * vals, size_t dim );$\indexc{bsearchu}$
     6817        E * bsearchu( E key, const E * vals, size_t dim );§\indexc{bsearchu}§
    68736818        size_t bsearchu( E key, const E * vals, size_t dim );
    68746819}
     
    68846829
    68856830forall( otype E | { int ?<?( E, E ); } ) {
    6886         void qsort( E * vals, size_t dim );$\indexc{qsort}$
     6831        void qsort( E * vals, size_t dim );§\indexc{qsort}§
    68876832}
    68886833\end{cfa}
     
    68936838\leavevmode
    68946839\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6895 unsigned char abs( signed char );$\indexc{abs}$
     6840unsigned char abs( signed char );§\indexc{abs}§
    68966841int abs( int );
    68976842unsigned long int abs( long int );
     
    69126857\leavevmode
    69136858\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6914 void srandom( unsigned int seed );$\indexc{srandom}$
    6915 char random( void );$\indexc{random}$
    6916 char random( char u ); $\C{// [0,u)}$
    6917 char random( char l, char u ); $\C{// [l,u)}$
     6859void srandom( unsigned int seed );§\indexc{srandom}§
     6860char random( void );§\indexc{random}§
     6861char random( char u ); §\C{// [0,u)}§
     6862char random( char l, char u ); §\C{// [l,u)}§
    69186863int random( void );
    6919 int random( int u ); $\C{// [0,u)}$
    6920 int random( int l, int u ); $\C{// [l,u)}$
     6864int random( int u ); §\C{// [0,u)}§
     6865int random( int l, int u ); §\C{// [l,u)}§
    69216866unsigned int random( void );
    6922 unsigned int random( unsigned int u ); $\C{// [0,u)}$
    6923 unsigned int random( unsigned int l, unsigned int u ); $\C{// [l,u)}$
     6867unsigned int random( unsigned int u ); §\C{// [0,u)}§
     6868unsigned int random( unsigned int l, unsigned int u ); §\C{// [l,u)}§
    69246869long int random( void );
    6925 long int random( long int u ); $\C{// [0,u)}$
    6926 long int random( long int l, long int u ); $\C{// [l,u)}$
     6870long int random( long int u ); §\C{// [0,u)}§
     6871long int random( long int l, long int u ); §\C{// [l,u)}§
    69276872unsigned long int random( void );
    6928 unsigned long int random( unsigned long int u ); $\C{// [0,u)}$
    6929 unsigned long int random( unsigned long int l, unsigned long int u ); $\C{// [l,u)}$
    6930 float random( void );                                            $\C{// [0.0, 1.0)}$
    6931 double random( void );                                           $\C{// [0.0, 1.0)}$
    6932 float _Complex random( void );                           $\C{// [0.0, 1.0)+[0.0, 1.0)i}$
    6933 double _Complex random( void );                          $\C{// [0.0, 1.0)+[0.0, 1.0)i}$
    6934 long double _Complex random( void );             $\C{// [0.0, 1.0)+[0.0, 1.0)i}$
     6873unsigned long int random( unsigned long int u ); §\C{// [0,u)}§
     6874unsigned long int random( unsigned long int l, unsigned long int u ); §\C{// [l,u)}§
     6875float random( void );                                            §\C{// [0.0, 1.0)}§
     6876double random( void );                                           §\C{// [0.0, 1.0)}§
     6877float _Complex random( void );                           §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
     6878double _Complex random( void );                          §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
     6879long double _Complex random( void );             §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
    69356880\end{cfa}
    69366881
     
    69406885\leavevmode
    69416886\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6942 forall( otype T | { int ?<?( T, T ); } ) T min( T t1, T t2 );$\indexc{min}$
    6943 forall( otype T | { int ?>?( T, T ); } ) T max( T t1, T t2 );$\indexc{max}$
    6944 forall( otype T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );$\indexc{clamp}$
    6945 forall( otype T ) void swap( T * t1, T * t2 );$\indexc{swap}$
     6887forall( otype T | { int ?<?( T, T ); } ) T min( T t1, T t2 );§\indexc{min}§
     6888forall( otype T | { int ?>?( T, T ); } ) T max( T t1, T t2 );§\indexc{max}§
     6889forall( otype T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );§\indexc{clamp}§
     6890forall( otype T ) void swap( T * t1, T * t2 );§\indexc{swap}§
    69466891\end{cfa}
    69476892
     
    69576902\leavevmode
    69586903\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6959 float ?%?( float, float );$\indexc{fmod}$
     6904float ?%?( float, float );§\indexc{fmod}§
    69606905float fmod( float, float );
    69616906double ?%?( double, double );
     
    69646909long double fmod( long double, long double );
    69656910
    6966 float remainder( float, float );$\indexc{remainder}$
     6911float remainder( float, float );§\indexc{remainder}§
    69676912double remainder( double, double );
    69686913long double remainder( long double, long double );
    69696914
    6970 float remquo( float, float, int * );$\indexc{remquo}$
     6915float remquo( float, float, int * );§\indexc{remquo}§
    69716916double remquo( double, double, int * );
    69726917long double remquo( long double, long double, int * );
     
    69756920[ int, long double ] remquo( long double, long double );
    69766921
    6977 float div( float, float, int * );$\indexc{div}$ $\C{// alternative name for remquo}$
     6922float div( float, float, int * );§\indexc{div}§ §\C{// alternative name for remquo}§
    69786923double div( double, double, int * );
    69796924long double div( long double, long double, int * );
     
    69826927[ int, long double ] div( long double, long double );
    69836928
    6984 float fma( float, float, float );$\indexc{fma}$
     6929float fma( float, float, float );§\indexc{fma}§
    69856930double fma( double, double, double );
    69866931long double fma( long double, long double, long double );
    69876932
    6988 float fdim( float, float );$\indexc{fdim}$
     6933float fdim( float, float );§\indexc{fdim}§
    69896934double fdim( double, double );
    69906935long double fdim( long double, long double );
    69916936
    6992 float nan( const char * );$\indexc{nan}$
     6937float nan( const char * );§\indexc{nan}§
    69936938double nan( const char * );
    69946939long double nan( const char * );
     
    70006945\leavevmode
    70016946\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7002 float exp( float );$\indexc{exp}$
     6947float exp( float );§\indexc{exp}§
    70036948double exp( double );
    70046949long double exp( long double );
     
    70076952long double _Complex exp( long double _Complex );
    70086953
    7009 float exp2( float );$\indexc{exp2}$
     6954float exp2( float );§\indexc{exp2}§
    70106955double exp2( double );
    70116956long double exp2( long double );
     
    70146959// long double _Complex exp2( long double _Complex );
    70156960
    7016 float expm1( float );$\indexc{expm1}$
     6961float expm1( float );§\indexc{expm1}§
    70176962double expm1( double );
    70186963long double expm1( long double );
    70196964
    7020 float pow( float, float );$\indexc{pow}$
     6965float pow( float, float );§\indexc{pow}§
    70216966double pow( double, double );
    70226967long double pow( long double, long double );
     
    70316976\leavevmode
    70326977\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7033 float log( float );$\indexc{log}$
     6978float log( float );§\indexc{log}§
    70346979double log( double );
    70356980long double log( long double );
     
    70386983long double _Complex log( long double _Complex );
    70396984
    7040 float log2( float );$\indexc{log2}$
     6985float log2( float );§\indexc{log2}§
    70416986double log2( double );
    70426987long double log2( long double );
     
    70456990// long double _Complex log2( long double _Complex );
    70466991
    7047 float log10( float );$\indexc{log10}$
     6992float log10( float );§\indexc{log10}§
    70486993double log10( double );
    70496994long double log10( long double );
     
    70526997// long double _Complex log10( long double _Complex );
    70536998
    7054 float log1p( float );$\indexc{log1p}$
     6999float log1p( float );§\indexc{log1p}§
    70557000double log1p( double );
    70567001long double log1p( long double );
    70577002
    7058 int ilogb( float );$\indexc{ilogb}$
     7003int ilogb( float );§\indexc{ilogb}§
    70597004int ilogb( double );
    70607005int ilogb( long double );
    70617006
    7062 float logb( float );$\indexc{logb}$
     7007float logb( float );§\indexc{logb}§
    70637008double logb( double );
    70647009long double logb( long double );
    70657010
    7066 float sqrt( float );$\indexc{sqrt}$
     7011float sqrt( float );§\indexc{sqrt}§
    70677012double sqrt( double );
    70687013long double sqrt( long double );
     
    70717016long double _Complex sqrt( long double _Complex );
    70727017
    7073 float cbrt( float );$\indexc{cbrt}$
     7018float cbrt( float );§\indexc{cbrt}§
    70747019double cbrt( double );
    70757020long double cbrt( long double );
    70767021
    7077 float hypot( float, float );$\indexc{hypot}$
     7022float hypot( float, float );§\indexc{hypot}§
    70787023double hypot( double, double );
    70797024long double hypot( long double, long double );
     
    70857030\leavevmode
    70867031\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7087 float sin( float );$\indexc{sin}$
     7032float sin( float );§\indexc{sin}§
    70887033double sin( double );
    70897034long double sin( long double );
     
    70927037long double _Complex sin( long double _Complex );
    70937038
    7094 float cos( float );$\indexc{cos}$
     7039float cos( float );§\indexc{cos}§
    70957040double cos( double );
    70967041long double cos( long double );
     
    70997044long double _Complex cos( long double _Complex );
    71007045
    7101 float tan( float );$\indexc{tan}$
     7046float tan( float );§\indexc{tan}§
    71027047double tan( double );
    71037048long double tan( long double );
     
    71067051long double _Complex tan( long double _Complex );
    71077052
    7108 float asin( float );$\indexc{asin}$
     7053float asin( float );§\indexc{asin}§
    71097054double asin( double );
    71107055long double asin( long double );
     
    71137058long double _Complex asin( long double _Complex );
    71147059
    7115 float acos( float );$\indexc{acos}$
     7060float acos( float );§\indexc{acos}§
    71167061double acos( double );
    71177062long double acos( long double );
     
    71207065long double _Complex acos( long double _Complex );
    71217066
    7122 float atan( float );$\indexc{atan}$
     7067float atan( float );§\indexc{atan}§
    71237068double atan( double );
    71247069long double atan( long double );
     
    71277072long double _Complex atan( long double _Complex );
    71287073
    7129 float atan2( float, float );$\indexc{atan2}$
     7074float atan2( float, float );§\indexc{atan2}§
    71307075double atan2( double, double );
    71317076long double atan2( long double, long double );
    71327077
    7133 float atan( float, float ); $\C{// alternative name for atan2}$
    7134 double atan( double, double );$\indexc{atan}$
     7078float atan( float, float ); §\C{// alternative name for atan2}§
     7079double atan( double, double );§\indexc{atan}§
    71357080long double atan( long double, long double );
    71367081\end{cfa}
     
    71417086\leavevmode
    71427087\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7143 float sinh( float );$\indexc{sinh}$
     7088float sinh( float );§\indexc{sinh}§
    71447089double sinh( double );
    71457090long double sinh( long double );
     
    71487093long double _Complex sinh( long double _Complex );
    71497094
    7150 float cosh( float );$\indexc{cosh}$
     7095float cosh( float );§\indexc{cosh}§
    71517096double cosh( double );
    71527097long double cosh( long double );
     
    71557100long double _Complex cosh( long double _Complex );
    71567101
    7157 float tanh( float );$\indexc{tanh}$
     7102float tanh( float );§\indexc{tanh}§
    71587103double tanh( double );
    71597104long double tanh( long double );
     
    71627107long double _Complex tanh( long double _Complex );
    71637108
    7164 float asinh( float );$\indexc{asinh}$
     7109float asinh( float );§\indexc{asinh}§
    71657110double asinh( double );
    71667111long double asinh( long double );
     
    71697114long double _Complex asinh( long double _Complex );
    71707115
    7171 float acosh( float );$\indexc{acosh}$
     7116float acosh( float );§\indexc{acosh}§
    71727117double acosh( double );
    71737118long double acosh( long double );
     
    71767121long double _Complex acosh( long double _Complex );
    71777122
    7178 float atanh( float );$\indexc{atanh}$
     7123float atanh( float );§\indexc{atanh}§
    71797124double atanh( double );
    71807125long double atanh( long double );
     
    71897134\leavevmode
    71907135\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7191 float erf( float );$\indexc{erf}$
     7136float erf( float );§\indexc{erf}§
    71927137double erf( double );
    71937138long double erf( long double );
     
    71967141long double _Complex erf( long double _Complex );
    71977142
    7198 float erfc( float );$\indexc{erfc}$
     7143float erfc( float );§\indexc{erfc}§
    71997144double erfc( double );
    72007145long double erfc( long double );
     
    72037148long double _Complex erfc( long double _Complex );
    72047149
    7205 float lgamma( float );$\indexc{lgamma}$
     7150float lgamma( float );§\indexc{lgamma}§
    72067151double lgamma( double );
    72077152long double lgamma( long double );
     
    72107155long double lgamma( long double, int * );
    72117156
    7212 float tgamma( float );$\indexc{tgamma}$
     7157float tgamma( float );§\indexc{tgamma}§
    72137158double tgamma( double );
    72147159long double tgamma( long double );
     
    72207165\leavevmode
    72217166\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7222 float floor( float );$\indexc{floor}$
     7167float floor( float );§\indexc{floor}§
    72237168double floor( double );
    72247169long double floor( long double );
    72257170
    7226 float ceil( float );$\indexc{ceil}$
     7171float ceil( float );§\indexc{ceil}§
    72277172double ceil( double );
    72287173long double ceil( long double );
    72297174
    7230 float trunc( float );$\indexc{trunc}$
     7175float trunc( float );§\indexc{trunc}§
    72317176double trunc( double );
    72327177long double trunc( long double );
    72337178
    7234 float rint( float );$\indexc{rint}$
     7179float rint( float );§\indexc{rint}§
    72357180long double rint( long double );
    72367181long int rint( float );
     
    72417186long long int rint( long double );
    72427187
    7243 long int lrint( float );$\indexc{lrint}$
     7188long int lrint( float );§\indexc{lrint}§
    72447189long int lrint( double );
    72457190long int lrint( long double );
     
    72487193long long int llrint( long double );
    72497194
    7250 float nearbyint( float );$\indexc{nearbyint}$
     7195float nearbyint( float );§\indexc{nearbyint}§
    72517196double nearbyint( double );
    72527197long double nearbyint( long double );
    72537198
    7254 float round( float );$\indexc{round}$
     7199float round( float );§\indexc{round}§
    72557200long double round( long double );
    72567201long int round( float );
     
    72617206long long int round( long double );
    72627207
    7263 long int lround( float );$\indexc{lround}$
     7208long int lround( float );§\indexc{lround}§
    72647209long int lround( double );
    72657210long int lround( long double );
     
    72747219\leavevmode
    72757220\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7276 float copysign( float, float );$\indexc{copysign}$
     7221float copysign( float, float );§\indexc{copysign}§
    72777222double copysign( double, double );
    72787223long double copysign( long double, long double );
    72797224
    7280 float frexp( float, int * );$\indexc{frexp}$
     7225float frexp( float, int * );§\indexc{frexp}§
    72817226double frexp( double, int * );
    72827227long double frexp( long double, int * );
    72837228
    7284 float ldexp( float, int );$\indexc{ldexp}$
     7229float ldexp( float, int );§\indexc{ldexp}§
    72857230double ldexp( double, int );
    72867231long double ldexp( long double, int );
    72877232
    7288 [ float, float ] modf( float );$\indexc{modf}$
     7233[ float, float ] modf( float );§\indexc{modf}§
    72897234float modf( float, float * );
    72907235[ double, double ] modf( double );
     
    72937238long double modf( long double, long double * );
    72947239
    7295 float nextafter( float, float );$\indexc{nextafter}$
     7240float nextafter( float, float );§\indexc{nextafter}§
    72967241double nextafter( double, double );
    72977242long double nextafter( long double, long double );
    72987243
    7299 float nexttoward( float, long double );$\indexc{nexttoward}$
     7244float nexttoward( float, long double );§\indexc{nexttoward}§
    73007245double nexttoward( double, long double );
    73017246long double nexttoward( long double, long double );
    73027247
    7303 float scalbn( float, int );$\indexc{scalbn}$
     7248float scalbn( float, int );§\indexc{scalbn}§
    73047249double scalbn( double, int );
    73057250long double scalbn( long double, int );
    73067251
    7307 float scalbln( float, long int );$\indexc{scalbln}$
     7252float scalbln( float, long int );§\indexc{scalbln}§
    73087253double scalbln( double, long int );
    73097254long double scalbln( long double, long int );
     
    73227267\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    73237268struct Duration {
    7324         int64_t tv; $\C{// nanoseconds}$
     7269        int64_t tv; §\C{// nanoseconds}§
    73257270};
    73267271
     
    74527397\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    74537398struct Time {
    7454         uint64_t tv; $\C{// nanoseconds since UNIX epoch}$
     7399        uint64_t tv; §\C{// nanoseconds since UNIX epoch}§
    74557400};
    74567401
     
    75237468\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    75247469struct Clock {
    7525         Duration offset; $\C{// for virtual clock: contains offset from real-time}$
    7526         int clocktype; $\C{// implementation only -1 (virtual), CLOCK\_REALTIME}$
     7470        Duration offset; §\C{// for virtual clock: contains offset from real-time}§
     7471        int clocktype; §\C{// implementation only -1 (virtual), CLOCK\_REALTIME}§
    75277472};
    75287473
     
    75327477void ?{}( Clock & clk, Duration adj );
    75337478
    7534 Duration getResNsec(); $\C{// with nanoseconds}$
    7535 Duration getRes(); $\C{// without nanoseconds}$
    7536 
    7537 Time getTimeNsec(); $\C{// with nanoseconds}$
    7538 Time getTime(); $\C{// without nanoseconds}$
     7479Duration getResNsec(); §\C{// with nanoseconds}§
     7480Duration getRes(); §\C{// without nanoseconds}§
     7481
     7482Time getTimeNsec(); §\C{// with nanoseconds}§
     7483Time getTime(); §\C{// without nanoseconds}§
    75397484Time getTime( Clock & clk );
    75407485Time ?()( Clock & clk );
     
    75527497
    75537498\begin{cfa}
    7554 void ?{}( Int * this ); $\C{// constructor/destructor}$
     7499void ?{}( Int * this ); §\C{// constructor/destructor}§
    75557500void ?{}( Int * this, Int init );
    75567501void ?{}( Int * this, zero_t );
     
    75617506void ^?{}( Int * this );
    75627507
    7563 Int ?=?( Int * lhs, Int rhs ); $\C{// assignment}$
     7508Int ?=?( Int * lhs, Int rhs ); §\C{// assignment}§
    75647509Int ?=?( Int * lhs, long int rhs );
    75657510Int ?=?( Int * lhs, unsigned long int rhs );
     
    75787523unsigned long int narrow( Int val );
    75797524
    7580 int ?==?( Int oper1, Int oper2 ); $\C{// comparison}$
     7525int ?==?( Int oper1, Int oper2 ); §\C{// comparison}§
    75817526int ?==?( Int oper1, long int oper2 );
    75827527int ?==?( long int oper2, Int oper1 );
     
    76147559int ?>=?( unsigned long int oper1, Int oper2 );
    76157560
    7616 Int +?( Int oper ); $\C{// arithmetic}$
     7561Int +?( Int oper ); §\C{// arithmetic}§
    76177562Int -?( Int oper );
    76187563Int ~?( Int oper );
     
    76967641Int ?>>=?( Int * lhs, mp_bitcnt_t shift );
    76977642
    7698 Int abs( Int oper ); $\C{// number functions}$
     7643Int abs( Int oper ); §\C{// number functions}§
    76997644Int fact( unsigned long int N );
    77007645Int gcd( Int oper1, Int oper2 );
     
    77087653Int sqrt( Int oper );
    77097654
    7710 forall( dtype istype | istream( istype ) ) istype * ?|?( istype * is, Int * mp );  $\C{// I/O}$
     7655forall( dtype istype | istream( istype ) ) istype * ?|?( istype * is, Int * mp );  §\C{// I/O}§
    77117656forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype * os, Int mp );
    77127657\end{cfa}
     
    77197664\hline
    77207665\begin{cfa}
    7721 #include <gmp>$\indexc{gmp}$
     7666#include <gmp>§\indexc{gmp}§
    77227667int main( void ) {
    77237668        sout | "Factorial Numbers";
     
    77337678&
    77347679\begin{cfa}
    7735 #include <gmp.h>$\indexc{gmp.h}$
     7680#include <gmp.h>§\indexc{gmp.h}§
    77367681int main( void ) {
    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 );
     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 );
    77417686        for ( unsigned int i = 1; i <= 40; i += 1 ) {
    7742                 @mpz_mul_ui@( fact, fact, i );
    7743                 @gmp_printf@( "%d %Zd\n", i, fact );
     7687                ®mpz_mul_ui®( fact, fact, i );
     7688                ®gmp_printf®( "%d %Zd\n", i, fact );
    77447689        }
    77457690}
     
    78067751\begin{cfa}[belowskip=0pt]
    78077752// implementation
    7808 struct Rational {$\indexc{Rational}$
    7809         long int numerator, denominator; $\C{// invariant: denominator > 0}$
     7753struct Rational {§\indexc{Rational}§
     7754        long int numerator, denominator; §\C{// invariant: denominator > 0}§
    78107755}; // Rational
    78117756
    7812 Rational rational(); $\C{// constructors}$
     7757Rational rational(); §\C{// constructors}§
    78137758Rational rational( long int n );
    78147759Rational rational( long int n, long int d );
     
    78167761void ?{}( Rational * r, one_t );
    78177762
    7818 long int numerator( Rational r ); $\C{// numerator/denominator getter/setter}$
     7763long int numerator( Rational r ); §\C{// numerator/denominator getter/setter}§
    78197764long int numerator( Rational r, long int n );
    78207765long int denominator( Rational r );
    78217766long int denominator( Rational r, long int d );
    78227767
    7823 int ?==?( Rational l, Rational r ); $\C{// comparison}$
     7768int ?==?( Rational l, Rational r ); §\C{// comparison}§
    78247769int ?!=?( Rational l, Rational r );
    78257770int ?<?( Rational l, Rational r );
     
    78287773int ?>=?( Rational l, Rational r );
    78297774
    7830 Rational -?( Rational r ); $\C{// arithmetic}$
     7775Rational -?( Rational r ); §\C{// arithmetic}§
    78317776Rational ?+?( Rational l, Rational r );
    78327777Rational ?-?( Rational l, Rational r );
     
    78347779Rational ?/?( Rational l, Rational r );
    78357780
    7836 double widen( Rational r ); $\C{// conversion}$
     7781double widen( Rational r ); §\C{// conversion}§
    78377782Rational narrow( double f, long int md );
    78387783
  • src/main.cc

    rf4eb705 rd4a4b17  
    99// Author           : Peter Buhr and Rob Schluntz
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb  8 21:10:16 2021
    13 // Update Count     : 642
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Dec  7 15:29:00 2020
     13// Update Count     : 639
    1414//
    1515
     
    492492
    493493static const char * description[] = {
    494         "diagnostic color: never, always, auto",                        // -c
     494        "diagnostic color: never, always, or auto.",            // -c
    495495        "wait for gdb to attach",                                                       // -g
    496         "print translator help message",                                        // -h
     496        "print 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         "do not generate prelude prototypes => prelude not printed", // -p
     502        "generate prototypes for prelude functions",            // -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: counters, heap, time, all, none", // -S
     508        "<option-list> enable profiling information:\n          counters,heap,time,all,none", // -S
    509509        "building cfa standard lib",                                            // -t
    510510        "",                                                                                                     // -w
Note: See TracChangeset for help on using the changeset viewer.