Changeset b067d9b for doc/user/user.tex


Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r7951100 rb067d9b  
    11%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2 %% 
     2%%
    33%% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    44%%
    55%% The contents of this file are covered under the licence agreement in the
    66%% file "LICENCE" distributed with Cforall.
    7 %% 
    8 %% user.tex -- 
    9 %% 
     7%%
     8%% user.tex --
     9%%
    1010%% Author           : Peter A. Buhr
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun May  6 10:33:53 2018
    14 %% Update Count     : 3319
     13%% Last Modified On : Sat Jul 13 18:36:18 2019
     14%% Update Count     : 3876
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    7272
    7373% Names used in the document.
    74 \newcommand{\Version}{\input{../../version}}
     74\newcommand{\Version}{\input{build/version}}
    7575\newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}}
    7676\newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
     
    146146\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.
    147147Like 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.
    148 The primary new features include parametric-polymorphic routines and types, exceptions, concurrency, and modules.
     148The primary new features include polymorphic routines and types, exceptions, concurrency, and modules.
    149149
    150150One of the main design philosophies of \CFA is to ``\Index{describe not prescribe}'', which means \CFA tries to provide a pathway from low-level C programming to high-level \CFA programming, but it does not force programmers to ``do the right thing''.
     
    155155As well, new programs can be written in \CFA using a combination of C and \CFA features.
    156156
    157 \Index*[C++]{\CC{}} had a similar goal 30 years ago, allowing object-oriented programming to be incrementally added to C.
    158 However, \CC currently has the disadvantages of a strong object-oriented bias, multiple legacy design-choices that cannot be updated, and active divergence of the language model from C, all of which requires significant effort and training to incrementally add \CC to a C-based project.
     157\Index*[C++]{\CC{}}~\cite{c++:v1} had a similar goal 30 years ago, allowing object-oriented programming to be incrementally added to C.
     158However, \CC currently has the disadvantages of a strong object-oriented bias, multiple legacy design-choices that cannot be updated, and active divergence of the language model from C, requiring significant effort and training to incrementally add \CC to a C-based project.
    159159In contrast, \CFA has 30 years of hindsight and a clean starting point.
    160160
    161161Like \Index*[C++]{\CC{}}, there may be both an old and new ways to achieve the same effect.
    162 For example, the following programs compare the \CFA, C, and \CC I/O mechanisms, where the programs output the same result.
    163 \begin{cquote}
     162For example, the following programs compare the C, \CFA, and \CC I/O mechanisms, where the programs output the same result.
     163\begin{center}
    164164\begin{tabular}{@{}l@{\hspace{1.5em}}l@{\hspace{1.5em}}l@{}}
    165165\multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{C}} & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{\CC}}      \\
     
    178178int main( void ) {
    179179        int x = 0, y = 1, z = 2;
    180         ®sout | x | y | z | endl;®§\indexc{sout}§
     180        ®sout | x | y | z;®§\indexc{sout}§
    181181}
    182182\end{cfa}
     
    191191\end{cfa}
    192192\end{tabular}
    193 \end{cquote}
     193\end{center}
    194194While 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}).
    195195
     196
    196197\subsection{Background}
    197198
    198199This document is a programmer reference-manual for the \CFA programming language.
    199 The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of each feature.
     200The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of features.
    200201The manual does not teach programming, \ie how to combine the new constructs to build complex programs.
    201 A reader should already have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented, as well as some experience programming in C/\CC.
     202The reader must have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented, as well as some experience programming in C/\CC.
    202203Implementers should refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
    203204Changes to the syntax and additional features are expected to be included in later revisions.
     
    206207\section{Why fix C?}
    207208
    208 The C programming language is a foundational technology for modern computing with millions of lines of code implementing everything from commercial operating-systems (especially UNIX systems) to hobby projects.
     209The 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.
    209210This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
    210211Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    211212For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice.
    212 The TIOBE index~\cite{TIOBE} for March 2016 showed the following programming-language popularity: \Index*{Java} 20.5\%, C 14.5\%, \Index*[C++]{\CC{}} 6.7\%, \Csharp 4.3\%, \Index*{Python} 4.3\%, where the next 50 languages are less than 3\% each with a long tail.
    213 As well, for 30 years, C has been the number 1 and 2 most popular programming language:
     213The TIOBE index~\cite{TIOBE} for July 2018 ranks the top five most \emph{popular} programming languages as \Index*{Java} 16\%, C 14\%, \Index*[C++]{\CC{}} 7.5\%, Python 6\%, Visual Basic 4\% = 47.5\%, where the next 50 languages are less than 4\% each, with a long tail.
     214The top 3 rankings over the past 30 years are:
    214215\begin{center}
    215 \setlength{\tabcolsep}{1.5ex}
    216 \begin{tabular}{@{}r|c|c|c|c|c|c|c@{}}
    217 Ranking & 2016  & 2011  & 2006  & 2001  & 1996  & 1991  & 1986          \\
    218 \hline
    219 Java    & 1             & 1             & 1             & 3             & 29    & -             & -                     \\
    220 \hline
    221 \R{C}   & \R{2} & \R{2} & \R{2} & \R{1} & \R{1} & \R{1} & \R{1}         \\
    222 \hline
    223 \CC             & 3             & 3             & 3             & 2             & 2             & 2             & 7                     \\
     216\setlength{\tabcolsep}{10pt}
     217\begin{tabular}{@{}rccccccc@{}}
     218                & 2018  & 2013  & 2008  & 2003  & 1998  & 1993  & 1988  \\ \hline
     219Java    & 1             & 2             & 1             & 1             & 16    & -             & -             \\
     220\R{C}   & \R{2} & \R{1} & \R{2} & \R{2} & \R{1} & \R{1} & \R{1} \\
     221\CC             & 3             & 4             & 3             & 3             & 2             & 2             & 5             \\
    224222\end{tabular}
    225223\end{center}
    226224Hence, C is still an extremely important programming language, with double the usage of \Index*[C++]{\CC{}}; in many cases, \CC is often used solely as a better C.
    227225Love it or hate it, C has been an important and influential part of computer science for 40 years and its appeal is not diminishing.
    228 Unfortunately, C has many problems and omissions that make it an unacceptable programming language for modern needs.
     226Nevertheless, C has many problems and omissions that make it an unacceptable programming language for modern needs.
    229227
    230228As stated, the goal of the \CFA project is to engineer modern language-features into C in an evolutionary rather than revolutionary way.
     
    236234These languages have different syntax and semantics from C, do not interoperate directly with C, and are not systems languages because of restrictive memory-management or garbage collection.
    237235As a result, there is a significant learning curve to move to these languages, and C legacy-code must be rewritten.
    238 These costs can be prohibitive for many companies with a large software-base in C/\CC, and a significant number of programmers require retraining to the new programming language.
    239 
    240 The 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 containing modern language-features.
    241 Without significant extension to the C programming language, it is becoming unable to cope with the needs of modern programming problems and programmers;
     236These costs can be prohibitive for many companies with a large software-base in C/\CC, and a significant number of programmers require retraining in the new programming language.
     237
     238The 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.
     239To achieve these goals required a significant engineering exercise, where we had to ``think inside the existing C box''.
     240Without these significant extension to C, it is unable to cope with the needs of modern programming problems and programmers;
    242241as a result, it will fade into disuse.
    243242Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern programming language.
     
    255254\begin{lstlisting}
    256255®forall( otype T )® T identity( T val ) { return val; }
    257 int forty_two = identity( 42 );                 §\C{// T is bound to int, forty\_two == 42}§
     256int forty_two = identity( 42 ); §\C{// T is bound to int, forty\_two == 42}§
    258257\end{lstlisting}
    259258% extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions.
     
    283282
    284283double key = 5.0, vals[10] = { /* 10 sorted floating values */ };
    285 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp );      §\C{// search sorted array}§
     284double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); §\C{// search sorted array}§
    286285\end{lstlisting}
    287286which can be augmented simply with a polymorphic, type-safe, \CFA-overloaded wrappers:
     
    292291
    293292forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {
    294         T * result = bsearch( key, arr, size ); §\C{// call first version}§
    295         return result ? result - arr : size; }  §\C{// pointer subtraction includes sizeof(T)}§
    296 
    297 double * val = bsearch( 5.0, vals, 10 );        §\C{// selection based on return type}§
     293        T * result = bsearch( key, arr, size ); §\C{// call first version}§
     294        return result ? result - arr : size; } §\C{// pointer subtraction includes sizeof(T)}§
     295
     296double * val = bsearch( 5.0, vals, 10 ); §\C{// selection based on return type}§
    298297int posn = bsearch( 5.0, vals, 10 );
    299298\end{lstlisting}
     
    307306\begin{lstlisting}
    308307forall( dtype T | sized(T) ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); }
    309 int * ip = malloc();                                    §\C{// select type and size from left-hand side}§
     308int * ip = malloc(); §\C{// select type and size from left-hand side}§
    310309double * dp = malloc();
    311310struct S {...} * sp = malloc();
     
    318317Whereas, \CFA wraps each of these routines into ones with the overloaded name ©abs©:
    319318\begin{cfa}
    320 char abs( char );
    321 ®extern "C" {® int abs( int ); ®}®              §\C{// use default C routine for int}§
    322 long int abs( long int );
    323 long long int abs( long long int );
    324 float abs( float );
    325 double abs( double );
    326 long double abs( long double );
    327 float _Complex abs( float _Complex );
    328 double _Complex abs( double _Complex );
    329 long double _Complex abs( long double _Complex );
     319char ®abs®( char );
     320extern "C" { int ®abs®( int ); } §\C{// use default C routine for int}§
     321long int ®abs®( long int );
     322long long int ®abs®( long long int );
     323float ®abs®( float );
     324double ®abs®( double );
     325long double ®abs®( long double );
     326float _Complex ®abs®( float _Complex );
     327double _Complex ®abs®( double _Complex );
     328long double _Complex ®abs®( long double _Complex );
    330329\end{cfa}
    331330The problem is the name clash between the library routine ©abs© and the \CFA names ©abs©.
    332331Hence, names appearing in an ©extern "C"© block have \newterm*{C linkage}.
    333332Then 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.
    334 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.
    335 There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and type.
     333Hence, 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.
     334There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and types.
    336335
    337336This example strongly illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
     
    350349\begin{description}
    351350\item
    352 \Indexc{-std=gnu99}\index{compilation option!-std=gnu99@{©-std=gnu99©}}
    353 The 1999 C standard plus GNU extensions.
    354 \item
    355 \Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]@-fgnu89-inline@}}
    356 Use the traditional GNU semantics for inline routines in C99 mode, which allows inline routines in header files.
     351\Indexc{-std=gnu11}\index{compilation option!-std=gnu11@{©-std=gnu11©}}
     352The 2011 C standard plus GNU extensions.
     353\item
     354\Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]$-fgnu89-inline$}}
     355Use the traditional GNU semantics for inline routines in C11 mode, which allows inline routines in header files.
    357356\end{description}
    358357The following new \CFA options are available:
     
    427426\begin{cfa}
    428427#ifndef __CFORALL__
    429 #include <stdio.h>§\indexc{stdio.h}§    §\C{// C header file}§
     428#include <stdio.h>§\indexc{stdio.h}§ §\C{// C header file}§
    430429#else
    431 #include <fstream>§\indexc{fstream}§    §\C{// \CFA header file}§
     430#include <fstream>§\indexc{fstream}§ §\C{// \CFA header file}§
    432431#endif
    433432\end{cfa}
    434 which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}.
     433which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}.
     434
     435The \CFA translator has multiple steps.
     436The following flags control how the tranlator works, the stages run, and printing within a stage.
     437The majority of these flags are used by \CFA developers, but some are occasionally useful to programmers.
     438\begin{description}[topsep=5pt,itemsep=0pt,parsep=0pt]
     439\item
     440\Indexc{-h}\index{translator option!-h@{©-h©}}, \Indexc{--help}\index{translator option!--help@{©--help©}} \, print help message
     441\item
     442\Indexc{-l}\index{translator option!-l@{©-l©}}, \Indexc{--libcfa}\index{translator option!--libcfa@{©--libcfa©}} \, generate libcfa.c
     443\item
     444\Indexc{-L}\index{translator option!-L@{©-L©}}, \Indexc{--linemarks}\index{translator option!--linemarks@{©--linemarks©}} \, generate line marks
     445\item
     446\Indexc{-m}\index{translator option!-m@{©-m©}}, \Indexc{--no-main}\index{translator option!--no-main@{©--no-main©}} \, do not replace main
     447\item
     448\Indexc{-N}\index{translator option!-N@{©-N©}}, \Indexc{--no-linemarks}\index{translator option!--no-linemarks@{©--no-linemarks©}} \, do not generate line marks
     449\item
     450\Indexc{-n}\index{translator option!-n@{©-n©}}, \Indexc{--no-prelude}\index{translator option!--no-prelude@{©--no-prelude©}} \, do not read prelude
     451\item
     452\Indexc{-p}\index{translator option!-p@{©-p©}}, \Indexc{--prototypes}\index{translator option!--prototypes@{©--prototypes©}} \, generate prototypes for prelude functions
     453\item
     454\Indexc{-P}\index{translator option!-P@{©-P©}}, \Indexc{--print}\index{translator option!--print@{©--print©}} \, one of:
     455\begin{description}[topsep=0pt,itemsep=0pt,parsep=0pt]
     456\item
     457\Indexc{altexpr}\index{translator option!-P@{©-P©}!©altexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, alternatives for expressions
     458\item
     459\Indexc{ascodegen}\index{translator option!-P@{©-P©}!©ascodegen©}\index{translator option!--print@{©-print©}!©ascodegen©} \, as codegen rather than AST
     460\item
     461\Indexc{ast}\index{translator option!-P@{©-P©}!©ast©}\index{translator option!--print@{©-print©}!©ast©} \, AST after parsing
     462\item
     463\Indexc{astdecl}\index{translator option!-P@{©-P©}!©astdecl©}\index{translator option!--print@{©-print©}!©astdecl©} \, AST after declaration validation pass
     464\item
     465\Indexc{asterr}\index{translator option!-P@{©-P©}!©asterr©}\index{translator option!--print@{©-print©}!©asterr©} \, AST on error
     466\item
     467\Indexc{astexpr}\index{translator option!-P@{©-P©}!©astexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, AST after expression analysis
     468\item
     469\Indexc{astgen}\index{translator option!-P@{©-P©}!©astgen©}\index{translator option!--print@{©-print©}!©astgen©} \, AST after instantiate generics
     470\item
     471\Indexc{box}\index{translator option!-P@{©-P©}!©box©}\index{translator option!--print@{©-print©}!©box©} \, before box step
     472\item
     473\Indexc{ctordtor}\index{translator option!-P@{©-P©}!©ctordtor©}\index{translator option!--print@{©-print©}!©ctordtor©} \, after ctor/dtor are replaced
     474\item
     475\Indexc{codegen}\index{translator option!-P@{©-P©}!©codegen©}\index{translator option!--print@{©-print©}!©codegen©} \, before code generation
     476\item
     477\Indexc{declstats}\index{translator option!-P@{©-P©}!©declstats©}\index{translator option!--print@{©-print©}!©declstats©} \, code property statistics
     478\item
     479\Indexc{parse}\index{translator option!-P@{©-P©}!©parse©}\index{translator option!--print@{©-print©}!©parse©} \, yacc (parsing) debug information
     480\item
     481\Indexc{pretty}\index{translator option!-P@{©-P©}!©pretty©}\index{translator option!--print@{©-print©}!©pretty©} \, prettyprint for ascodegen flag
     482\item
     483\Indexc{resolver}\index{translator option!-P@{©-P©}!©resolver©}\index{translator option!--print@{©-print©}!©resolver©} \, before resolver step
     484\item
     485\Indexc{rproto}\index{translator option!-P@{©-P©}!©rproto©}\index{translator option!--print@{©-print©}!©rproto©} \, resolver-proto instance
     486\item
     487\Indexc{rsteps}\index{translator option!-P@{©-P©}!©rsteps©}\index{translator option!--print@{©-print©}!©rsteps©} \, resolver steps
     488\item
     489\Indexc{symevt}\index{translator option!-P@{©-P©}!©symevt©}\index{translator option!--print@{©-print©}!©symevt©} \, symbol table events
     490\item
     491\Indexc{tree}\index{translator option!-P@{©-P©}!©tree©}\index{translator option!--print@{©-print©}!©tree©} \, parse tree
     492\item
     493\Indexc{tuple}\index{translator option!-P@{©-P©}!©tuple©}\index{translator option!--print@{©-print©}!©tuple©} \, after tuple expansion
     494\end{description}
     495\item
     496\Indexc{--prelude-dir} <directory> \, prelude directory for debug/nodebug
     497\item
     498\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:
     499\begin{description}[topsep=0pt,itemsep=0pt,parsep=0pt]
     500\item
     501\Indexc{counters,heap,time,all,none}
     502\end{description}
     503\item
     504\Indexc{-t}\index{translator option!-t@{©-t©}}, \Indexc{--tree}\index{translator option!--tree@{©--tree©}} build in tree
     505\end{description}
     506
     507
     508\section{Backquote Identifiers}
     509\label{s:BackquoteIdentifiers}
     510
     511\CFA introduces several new keywords (see \VRef{s:CFAKeywords}) that can clash with existing C variable-names in legacy code.
     512Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
     513\begin{cfa}
     514int ®`®otype®`® = 3; §\C{// make keyword an identifier}§
     515double ®`®forall®`® = 3.5;
     516\end{cfa}
     517
     518Existing 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.
     519\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©.
     520Several common C header-files with keyword clashes are fixed in the standard \CFA header-library, so there is a seamless programming-experience.
     521
     522\begin{figure}
     523\begin{cfa}
     524// include file uses the CFA keyword "with".
     525#if ! defined( with ) §\C{// nesting ?}§
     526#define with ®`®with®`® §\C{// make keyword an identifier}§
     527#define __CFA_BFD_H__
     528#endif
     529
     530®#include_next <bfdlink.h> §\C{// must have internal check for multiple expansion}§
     531®
     532#if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§
     533#undef with
     534#undef __CFA_BFD_H__
     535#endif
     536\end{cfa}
     537\caption{Header-File Interposition}
     538\label{f:HeaderFileInterposition}
     539\end{figure}
    435540
    436541
     
    439544Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore}, \eg:
    440545\begin{cfa}
    441 2®_®147®_®483®_®648;                                    §\C{// decimal constant}§
    442 56®_®ul;                                                                §\C{// decimal unsigned long constant}§
    443 0®_®377;                                                                §\C{// octal constant}§
    444 0x®_®ff®_®ff;                                                   §\C{// hexadecimal constant}§
    445 0x®_®ef3d®_®aa5c;                                               §\C{// hexadecimal constant}§
    446 3.141®_®592®_®654;                                              §\C{// floating constant}§
    447 10®_®e®_®+1®_®00;                                               §\C{// floating constant}§
    448 0x®_®ff®_®ff®_®p®_®3;                                   §\C{// hexadecimal floating}§
    449 0x®_®1.ffff®_®ffff®_®p®_®128®_®l;               §\C{// hexadecimal floating long constant}§
    450 L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§;     §\C{// wide character constant}§
     5462®_®147®_®483®_®648; §\C{// decimal constant}§
     54756®_®ul; §\C{// decimal unsigned long constant}§
     5480®_®377; §\C{// octal constant}§
     5490x®_®ff®_®ff; §\C{// hexadecimal constant}§
     5500x®_®ef3d®_®aa5c; §\C{// hexadecimal constant}§
     5513.141®_®592®_®654; §\C{// floating constant}§
     55210®_®e®_®+1®_®00; §\C{// floating constant}§
     5530x®_®ff®_®ff®_®p®_®3; §\C{// hexadecimal floating}§
     5540x®_®1.ffff®_®ffff®_®p®_®128®_®l; §\C{// hexadecimal floating long constant}§
     555L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§; §\C{// wide character constant}§
    451556\end{cfa}
    452557The rules for placement of underscores are:
     
    469574
    470575
    471 \section{Backquote Identifiers}
    472 \label{s:BackquoteIdentifiers}
    473 
    474 \CFA introduces several new keywords (see \VRef{s:CFAKeywords}) that can clash with existing C variable-names in legacy code.
    475 Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    476 \begin{cfa}
    477 int ®`®otype®`® = 3;                    §\C{// make keyword an identifier}§
    478 double ®`®forall®`® = 3.5;
    479 \end{cfa}
    480 
    481 Existing 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.
    482 \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©.
    483 Several common C header-files with keyword clashes are fixed in the standard \CFA header-library, so there is a seamless programming-experience.
     576\section{Exponentiation Operator}
     577
     578C, \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}, to perform the exponentiation operation.
     579\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$.
     580The 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)©.
     581
     582As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
     583Integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication\footnote{The multiplication computation is $O(\log y)$.} (or shifting if the exponent is 2).
     584Overflow from large exponents or negative exponents return zero.
     585Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
     586\begin{cfa}
     587sout | 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
     588           | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
     5891 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
     590\end{cfa}
     591Note, ©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.
     592Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
     593The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
     594\begin{cfa}
     595forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
     596OT ?®\®?( OT ep, unsigned int y );
     597forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
     598OT ?®\®?( OT ep, unsigned long int y );
     599\end{cfa}
     600The user type ©T© must define multiplication, one, ©1©, and, ©*©.
     601
     602
     603\section{Control Structures}
     604
     605\CFA identifies inconsistent, problematic, and missing control structures in C, and extends, modifies, and adds control structures to increase functionality and safety.
     606
     607
     608%\subsection{\texorpdfstring{\protect\lstinline@if@/\protect\lstinline@while@ Statement}{if Statement}}
     609\subsection{\texorpdfstring{\LstKeywordStyle{if}/\LstKeywordStyle{while} Statement}{if/while Statement}}
     610
     611The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.
     612(Does not make sense for ©do©-©while©.)
     613\begin{cfa}
     614if ( ®int x = f()® ) ... §\C{// x != 0}§
     615if ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
     616if ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
     617if ( ®struct S { int i; } x = { f() }; x.i < 4® ) §\C{// relational expression}§
     618
     619while ( ®int x = f()® ) ... §\C{// x != 0}§
     620while ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
     621while ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
     622while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}§
     623\end{cfa}
     624Unless 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.}
     625The scope of the declaration(s) is local to the @if@ statement but exist within both the ``then'' and ``else'' clauses.
     626
     627
     628\subsection{Loop Control}
     629
     630The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
     631\begin{itemize}
     632\item
     633An empty conditional implies ©1©.
     634\item
     635The up-to range ©~©\index{~@©~©} means exclusive range [M,N).
     636\item
     637The up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
     638\item
     639The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M).
     640\item
     641The down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M].
     642\item
     643©@© means put nothing in this field.
     644\item
     645©0© is the implicit start value;
     646\item
     647©1© is the implicit increment value.
     648\item
     649The up-to range uses ©+=© for increment;
     650\item
     651The down-to range uses ©-=© for decrement.
     652\item
     653The loop index is polymorphic in the type of the start value or comparison value when start is implicitly ©0©.
     654\end{itemize}
    484655
    485656\begin{figure}
    486 \begin{cfa}
    487 // include file uses the CFA keyword "with".
    488 #if ! defined( with )                   §\C{// nesting ?}§
    489 #define with ®`®with®`®                 §\C{// make keyword an identifier}§
    490 #define __CFA_BFD_H__
    491 #endif
    492 
    493 ®#include_next <bfdlink.h>              §\C{// must have internal check for multiple expansion}§
    494 ®
    495 #if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§
    496 #undef with
    497 #undef __CFA_BFD_H__
    498 #endif
    499 \end{cfa}
    500 \caption{Header-File Interposition}
    501 \label{f:HeaderFileInterposition}
     657\begin{cquote}
     658\begin{tabular}{@{}l|l@{}}
     659\multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
     660\hline
     661\begin{cfa}
     662sout | nlOff;
     663while ®()® { sout | "empty"; break; } sout | nl;
     664do { sout | "empty"; break; } while ®()®; sout | nl;
     665for ®()® { sout | "empty"; break; } sout | nl;
     666for ( ®0® ) { sout | "A"; } sout | "zero" | nl;
     667for ( ®1® ) { sout | "A"; } sout | nl;
     668for ( ®10® ) { sout | "A"; } sout | nl;
     669for ( ®1 ~= 10 ~ 2® ) { sout | "B"; } sout | nl;
     670for ( ®10 -~= 1 ~ 2® ) { sout | "C"; } sout | nl;
     671for ( ®0.5 ~ 5.5® ) { sout | "D"; } sout | nl;
     672for ( ®5.5 -~ 0.5® ) { sout | "E"; } sout | nl;
     673for ( ®i; 10® ) { sout | i; } sout | nl;
     674for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; } sout | nl;
     675for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; } sout | nl;
     676for ( ®i; 0.5 ~ 5.5® ) { sout | i; } sout | nl;
     677for ( ®i; 5.5 -~ 0.5® ) { sout | i; } sout | nl;
     678for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; } sout | nl;
     679for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; } sout | nl;
     680enum { N = 10 };
     681for ( ®N® ) { sout | "N"; } sout | nl;
     682for ( ®i; N® ) { sout | i; } sout | nl;
     683for ( ®i; N -~ 0® ) { sout | i; } sout | nl;
     684const int start = 3, comp = 10, inc = 2;
     685for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; } sout | nl;
     686for ( ®i; 1 ~ @® ) { if ( i > 10 ) break;
     687        sout | i; } sout | nl;
     688for ( ®i; 10 -~ @® ) { if ( i < 0 ) break;
     689        sout | i; } sout | nl;
     690for ( ®i; 2 ~ @ ~ 2® ) { if ( i > 10 ) break;
     691        sout | i; } sout | nl;
     692for ( ®i; 2.1 ~ @ ~ @® ) { if ( i > 10.5 ) break;
     693        sout | i; i += 1.7; } sout | nl;
     694for ( ®i; 10 -~ @ ~ 2® ) { if ( i < 0 ) break;
     695        sout | i; } sout | nl;
     696for ( ®i; 12.1 ~ @ ~ @® ) { if ( i < 2.5 ) break;
     697        sout | i; i -= 1.7; } sout | nl;
     698for ( ®i; 5 : j; -5 ~ @® ) { sout | i | j; } sout | nl;
     699for ( ®i; 5 : j; -5 -~ @® ) { sout | i | j; } sout | nl;
     700for ( ®i; 5 : j; -5 ~ @ ~ 2® ) { sout | i | j; } sout | nl;
     701for ( ®i; 5 : j; -5 -~ @ ~ 2® ) { sout | i | j; } sout | nl;
     702for ( ®j; -5 ~ @ : i; 5® ) { sout | i | j; } sout | nl;
     703for ( ®j; -5 -~ @ : i; 5® ) { sout | i | j; } sout | nl;
     704for ( ®j; -5 ~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
     705for ( ®j; -5 -~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
     706for ( ®j; -5 -~ @ ~ 2 : i; 5 : k; 1.5 ~ @® ) {
     707        sout | i | j | k; } sout | nl;
     708for ( ®j; -5 -~ @ ~ 2 : k; 1.5 ~ @ : i; 5® ) {
     709        sout | i | j | k; } sout | nl;
     710for ( ®k; 1.5 ~ @ : j; -5 -~ @ ~ 2 : i; 5® ) {
     711        sout | i | j | k; } sout | nl;
     712\end{cfa}
     713&
     714\begin{cfa}
     715
     716empty
     717empty
     718empty
     719zero
     720A
     721A A A A A A A A A A
     722B B B B B
     723C C C C C
     724D D D D D
     725E E E E E
     7260 1 2 3 4 5 6 7 8 9
     7271 3 5 7 9
     72810 8 6 4 2
     7290.5 1.5 2.5 3.5 4.5
     7305.5 4.5 3.5 2.5 1.5
     7312 4 6 8 10
     73210 8 6 4 2
     733
     734N N N N N N N N N N
     7350 1 2 3 4 5 6 7 8 9
     73610 9 8 7 6 5 4 3 2 1
     737
     7383 6 9
     739
     7401 2 3 4 5 6 7 8 9 10
     741
     74210 9 8 7 6 5 4 3 2 1 0
     743
     7442 4 6 8 10
     745
     7462.1 3.8 5.5 7.2 8.9
     747
     74810 8 6 4 2 0
     749
     75012.1 10.4 8.7 7 5.3 3.6
     7510 -5 1 -4 2 -3 3 -2 4 -1
     7520 -5 1 -6 2 -7 3 -8 4 -9
     7530 -5 1 -3 2 -1 3 1 4 3
     7540 -5 1 -7 2 -9 3 -11 4 -13
     7550 -5 1 -4 2 -3 3 -2 4 -1
     7560 -5 1 -6 2 -7 3 -8 4 -9
     7570 -5 1 -3 2 -1 3 1 4 3
     7580 -5 1 -7 2 -9 3 -11 4 -13
     759
     7600 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     761
     7620 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     763
     7640 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     765\end{cfa}
     766\end{tabular}
     767\end{cquote}
     768\caption{Loop Control Examples}
     769\label{f:LoopControlExamples}
    502770\end{figure}
    503771
    504772
    505 \section{Exponentiation Operator}
    506 
    507 C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation.
    508 \CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@\lstinline@?\?@} and ©?\=?©\index{?\\=?@\lstinline@?\=?@}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
    509 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)©.
    510 
    511 As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
    512 Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication\footnote{The multiplication computation is $O(\log y)$.} (or shifting if the base is 2).
    513 Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating result because $x^{-y}=1/x^y$.
    514 Hence, it is important to designate exponent integral-constants as unsigned or signed: ©3 \ 3u© return an integral result, while ©3 \ 3© returns a floating result.
    515 Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
    516 \begin{cfa}
    517 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
    518 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
    519 \end{cfa}
    520 Parenthesis are necessary for the complex constants or the expresion is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
    521 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available.
    522 For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©;
    523 for returning a floating value, an additional divide of type ©T© into a ©double© returning a ©double© (©double ?/?( double, T )©) is necessary for negative exponents.
    524 
    525 
    526 \section{\texorpdfstring{Labelled \protect\lstinline@continue@ / \protect\lstinline@break@}{Labelled continue / break}}
     773%\section{\texorpdfstring{\protect\lstinline@switch@ Statement}{switch Statement}}
     774\subsection{\texorpdfstring{\LstKeywordStyle{switch} Statement}{switch Statement}}
     775
     776C allows a number of questionable forms for the ©switch© statement:
     777\begin{enumerate}
     778\item
     779By default, the end of a ©case© clause\footnote{
     780In this section, the term \emph{case clause} refers to either a ©case© or ©default© clause.}
     781\emph{falls through} to the next ©case© clause in the ©switch© statement;
     782to exit a ©switch© statement from a ©case© clause requires explicitly terminating the clause with a transfer statement, most commonly ©break©:
     783\begin{cfa}
     784switch ( i ) {
     785  case 1:
     786        ...
     787        // fall-through
     788  case 2:
     789        ...
     790        break;  // exit switch statement
     791}
     792\end{cfa}
     793The ability to fall-through to the next clause \emph{is} a useful form of control flow, specifically when a sequence of case actions compound:
     794\begin{cquote}
     795\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
     796\begin{cfa}
     797switch ( argc ) {
     798  case 3:
     799        // open output file
     800        // fall-through
     801  case 2:
     802        // open input file
     803        break;  // exit switch statement
     804  default:
     805        // usage message
     806}
     807\end{cfa}
     808&
     809\begin{cfa}
     810
     811if ( argc == 3 ) {
     812        // open output file
     813        ®// open input file
     814®} else if ( argc == 2 ) {
     815        ®// open input file (duplicate)
     816
     817®} else {
     818        // usage message
     819}
     820\end{cfa}
     821\end{tabular}
     822\end{cquote}
     823In this example, case 2 is always done if case 3 is done.
     824This 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.
     825C also uses fall-through to handle multiple case-values resulting in the same action:
     826\begin{cfa}
     827switch ( i ) {
     828  ®case 1: case 3: case 5:®     // odd values
     829        // odd action
     830        break;
     831  ®case 2: case 4: case 6:®     // even values
     832        // even action
     833        break;
     834}
     835\end{cfa}
     836However, this situation is handled in other languages without fall-through by allowing a list of case values.
     837While 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.
     838Hence, 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.
     839
     840\item
     841It is possible to place ©case© clauses on statements nested \emph{within} the body of the ©switch© statement:
     842\begin{cfa}
     843switch ( i ) {
     844  case 0:
     845        if ( j < k ) {
     846                ...
     847          ®case 1:®             // transfer into "if" statement
     848                ...
     849        } // if
     850  case 2:
     851        while ( j < 5 ) {
     852                ...
     853          ®case 3:®             // transfer into "while" statement
     854                ...
     855        } // while
     856} // switch
     857\end{cfa}
     858The problem with this usage is branching into control structures, which is known to cause both comprehension and technical difficulties.
     859The comprehension problem occurs from the inability to determine how control reaches a particular point due to the number of branches leading to it.
     860The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
     861There are no positive arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
     862Nevertheless, C does have an idiom where this capability is used, known as ``\Index*{Duff's device}''~\cite{Duff83}:
     863\begin{cfa}
     864register int n = (count + 7) / 8;
     865switch ( count % 8 ) {
     866case 0: do{ *to = *from++;
     867case 7:         *to = *from++;
     868case 6:         *to = *from++;
     869case 5:         *to = *from++;
     870case 4:         *to = *from++;
     871case 3:         *to = *from++;
     872case 2:         *to = *from++;
     873case 1:         *to = *from++;
     874                } while ( --n > 0 );
     875}
     876\end{cfa}
     877which unrolls a loop N times (N = 8 above) and uses the ©switch© statement to deal with any iterations not a multiple of N.
     878While efficient, this sort of special purpose usage is questionable:
     879\begin{quote}
     880Disgusting, no? But it compiles and runs just fine. I feel a combination of pride and revulsion at this
     881discovery.~\cite{Duff83}
     882\end{quote}
     883\item
     884It is possible to place the ©default© clause anywhere in the list of labelled clauses for a ©switch© statement, rather than only at the end.
     885Virtually all programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
     886The logic for this semantics is that after checking all the ©case© clauses without success, the ©default© clause is selected;
     887hence, physically placing the ©default© clause at the end of the ©case© clause list matches with this semantics.
     888This physical placement can be compared to the physical placement of an ©else© clause at the end of a series of connected ©if©/©else© statements.
     889
     890\item
     891It is possible to place unreachable code at the start of a ©switch© statement, as in:
     892\begin{cfa}
     893switch ( x ) {
     894        ®int y = 1;® §\C{// unreachable initialization}§
     895        ®x = 7;® §\C{// unreachable code without label/branch}§
     896  case 0: ...
     897        ...
     898        ®int z = 0;® §\C{// unreachable initialization, cannot appear after case}§
     899        z = 2;
     900  case 1:
     901        ®x = z;® §\C{// without fall through, z is uninitialized}§
     902}
     903\end{cfa}
     904While 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.
     905Furthermore, 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.
     906As 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.
     907The key observation is that the ©switch© statement branches into control structure, \ie there are multiple entry points into its statement body.
     908\end{enumerate}
     909
     910Before discussing potential language changes to deal with these problems, it is worth observing that in a typical C program:
     911\begin{itemize}
     912\item
     913the number of ©switch© statements is small,
     914\item
     915most ©switch© statements are well formed (\ie no \Index*{Duff's device}),
     916\item
     917the ©default© clause is usually written as the last case-clause,
     918\item
     919and there is only a medium amount of fall-through from one ©case© clause to the next, and most of these result from a list of case values executing common code, rather than a sequence of case actions that compound.
     920\end{itemize}
     921These observations put into perspective the \CFA changes to the ©switch©.
     922\begin{enumerate}
     923\item
     924Eliminating default fall-through has the greatest potential for affecting existing code.
     925However, even if fall-through is removed, most ©switch© statements would continue to work because of the explicit transfers already present at the end of each ©case© clause, the common placement of the ©default© clause at the end of the case list, and the most common use of fall-through, \ie a list of ©case© clauses executing common code, \eg:
     926\begin{cfa}
     927case 1:  case 2:  case 3: ...
     928\end{cfa}
     929still works.
     930Nevertheless, reversing the default action would have a non-trivial effect on case actions that compound, such as the above example of processing shell arguments.
     931Therefore, 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:
     932\begin{cfa}
     933®choose® ( i ) {
     934  case 1:  case 2:  case 3:
     935        ...
     936        ®// implicit end of switch (break)
     937  ®case 5:
     938        ...
     939        ®fallthru®; §\C{// explicit fall through}§
     940  case 7:
     941        ...
     942        ®break® §\C{// explicit end of switch (redundant)}§
     943  default:
     944        j = 3;
     945}
     946\end{cfa}
     947Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses;
     948An implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.
     949An 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.
     950As well, allowing an explicit ©break© from the ©choose© is a carry over from the ©switch© statement, and expected by C programmers.
     951\item
     952\Index*{Duff's device} is eliminated from both ©switch© and ©choose© statements, and only invalidates a small amount of very questionable code.
     953Hence, the ©case© clause must appear at the same nesting level as the ©switch©/©choose© body, as is done in most other programming languages with ©switch© statements.
     954\item
     955The issue of ©default© at locations other than at the end of the cause clause can be solved by using good programming style, and there are a few reasonable situations involving fall-through where the ©default© clause needs to appear is locations other than at the end.
     956Therefore, no change is made for this issue.
     957\item
     958Dealing with unreachable code in a ©switch©/©choose© body is solved by restricting declarations and associated initialization to the start of statement body, which is executed \emph{before} the transfer to the appropriate ©case© clause\footnote{
     959Essentially, these declarations are hoisted before the ©switch©/©choose© statement and both declarations and statement are surrounded by a compound statement.} and precluding statements before the first ©case© clause.
     960Further declarations at the same nesting level as the statement body are disallowed to ensure every transfer into the body is sound.
     961\begin{cfa}
     962switch ( x ) {
     963        ®int i = 0;® §\C{// allowed only at start}§
     964  case 0:
     965        ...
     966        ®int j = 0;® §\C{// disallowed}§
     967  case 1:
     968        {
     969                ®int k = 0;® §\C{// allowed at different nesting levels}§
     970                ...
     971          ®case 2:® §\C{// disallow case in nested statements}§
     972        }
     973  ...
     974}
     975\end{cfa}
     976\end{enumerate}
     977
     978
     979%\section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}}
     980\subsection{\texorpdfstring{\LstKeywordStyle{case} Statement}{case Statement}}
     981
     982C restricts the ©case© clause of a ©switch© statement to a single value.
     983For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values.
     984Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C.
     985Therefore, the ©case© clause is extended with a list of values, as in:
     986\begin{cquote}
     987\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
     988\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     989\begin{cfa}
     990switch ( i ) {
     991  case ®1, 3, 5®:
     992        ...
     993  case ®2, 4, 6®:
     994        ...
     995}
     996\end{cfa}
     997&
     998\begin{cfa}
     999switch ( i ) {
     1000  case 1: case 3 : case 5:
     1001        ...
     1002  case 2: case 4 : case 6:
     1003        ...
     1004}
     1005\end{cfa}
     1006&
     1007\begin{cfa}
     1008
     1009// odd values
     1010
     1011// even values
     1012
     1013
     1014\end{cfa}
     1015\end{tabular}
     1016\end{cquote}
     1017In addition, subranges are allowed to specify case values.\footnote{
     1018gcc has the same mechanism but awkward syntax, \lstinline@2 ...42@, because a space is required after a number, otherwise the period is a decimal point.}
     1019\begin{cfa}
     1020switch ( i ) {
     1021  case ®1~5:® §\C{// 1, 2, 3, 4, 5}§
     1022        ...
     1023  case ®10~15:® §\C{// 10, 11, 12, 13, 14, 15}§
     1024        ...
     1025}
     1026\end{cfa}
     1027Lists of subranges are also allowed.
     1028\begin{cfa}
     1029case ®1~5, 12~21, 35~42®:
     1030\end{cfa}
     1031
     1032
     1033% for ()  => for ( ;; )
     1034% for ( 10 - t ) => for ( typeof(10 - t) ? = 0 ; ? < 10 - t; ? += 1 ) // using 0 and 1
     1035% for ( i ; 10 - t ) => for ( typeof(10 - t) i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1
     1036% for ( T i ; 10 - t ) => for ( T i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1
     1037% for ( 3~9 ) => for ( int ? = 3 ; ? < 9; ? += 1 ) // using 1
     1038% for ( i ; 3~9 ) => for ( int i = 3 ; i < 9; i += 1 ) // using 1
     1039% for ( T i ; 3~9 ) => for ( T i = 3 ; i < 9; i += 1 ) // using 1
     1040
     1041
     1042%\subsection{\texorpdfstring{Labelled \protect\lstinline@continue@ / \protect\lstinline@break@}{Labelled continue / break}}
     1043\subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}}
    5271044
    5281045While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure.
    5291046Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    530 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@\lstinline@continue@!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@\lstinline@break@!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}, as in Java.
     1047To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@©break©!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}, as in Java.
    5311048For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    5321049for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
     
    6131130\end{figure}
    6141131
    615 Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline@goto@!restricted} restricted in the following ways:
     1132Both labelled ©continue© and ©break© are a ©goto©\index{goto@©goto©!restricted} restricted in the following ways:
    6161133\begin{itemize}
    6171134\item
     
    6261143With ©goto©, the label is at the end of the control structure, which fails to convey this important clue early enough to the reader.
    6271144Finally, using an explicit target for the transfer instead of an implicit target allows new constructs to be added or removed without affecting existing constructs.
    628 The implicit targets of the current ©continue© and ©break©, \ie the closest enclosing loop or ©switch©, change as certain constructs are added or removed.
    629 
    630 
    631 \section{\texorpdfstring{\protect\lstinline@switch@ Statement}{switch Statement}}
    632 
    633 C allows a number of questionable forms for the ©switch© statement:
    634 \begin{enumerate}
    635 \item
    636 By default, the end of a ©case© clause\footnote{
    637 In this section, the term \emph{case clause} refers to either a ©case© or ©default© clause.}
    638 \emph{falls through} to the next ©case© clause in the ©switch© statement;
    639 to exit a ©switch© statement from a ©case© clause requires explicitly terminating the clause with a transfer statement, most commonly ©break©:
    640 \begin{cfa}
    641 switch ( i ) {
    642   case 1:
    643         ...
    644         // fall-through
    645   case 2:
    646         ...
    647         break;  // exit switch statement
    648 }
    649 \end{cfa}
    650 The ability to fall-through to the next clause \emph{is} a useful form of control flow, specifically when a sequence of case actions compound:
    651 \begin{cquote}
    652 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    653 \begin{cfa}
    654 switch ( argc ) {
    655   case 3:
    656         // open output file
    657         // fall-through
    658   case 2:
    659         // open input file
    660         break;  // exit switch statement
    661   default:
    662         // usage message
    663 }
    664 \end{cfa}
    665 &
    666 \begin{cfa}
    667 
    668 if ( argc == 3 ) {
    669         // open output file
    670         ®// open input file
    671 ®} else if ( argc == 2 ) {
    672         ®// open input file (duplicate)
    673 
    674 ®} else {
    675         // usage message
    676 }
    677 \end{cfa}
    678 \end{tabular}
    679 \end{cquote}
    680 In this example, case 2 is always done if case 3 is done.
    681 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.
    682 C also uses fall-through to handle multiple case-values resulting in the same action:
    683 \begin{cfa}
    684 switch ( i ) {
    685   ®case 1: case 3: case 5:®     // odd values
    686         // odd action
    687         break;
    688   ®case 2: case 4: case 6:®     // even values
    689         // even action
    690         break;
    691 }
    692 \end{cfa}
    693 However, this situation is handled in other languages without fall-through by allowing a list of case values.
    694 While fall-through itself is not a problem, the problem occurs when fall-through is the default, as this semantics is unintuitive to many programmers and is different from virtually all other programming languages with a ©switch© statement.
    695 Hence, 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.
    696 
    697 \item
    698 It is possible to place ©case© clauses on statements nested \emph{within} the body of the ©switch© statement:
    699 \begin{cfa}
    700 switch ( i ) {
    701   case 0:
    702         if ( j < k ) {
    703                 ...
    704           ®case 1:®             // transfer into "if" statement
    705                 ...
    706         } // if
    707   case 2:
    708         while ( j < 5 ) {
    709                 ...
    710           ®case 3:®             // transfer into "while" statement
    711                 ...
    712         } // while
    713 } // switch
    714 \end{cfa}
    715 The problem with this usage is branching into control structures, which is known to cause both comprehension and technical difficulties.
    716 The comprehension problem occurs from the inability to determine how control reaches a particular point due to the number of branches leading to it.
    717 The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
    718 There are no positive arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
    719 Nevertheless, C does have an idiom where this capability is used, known as ``\Index*{Duff's device}''~\cite{Duff83}:
    720 \begin{cfa}
    721 register int n = (count + 7) / 8;
    722 switch ( count % 8 ) {
    723 case 0: do{ *to = *from++;
    724 case 7:         *to = *from++;
    725 case 6:         *to = *from++;
    726 case 5:         *to = *from++;
    727 case 4:         *to = *from++;
    728 case 3:         *to = *from++;
    729 case 2:         *to = *from++;
    730 case 1:         *to = *from++;
    731                 } while ( --n > 0 );
    732 }
    733 \end{cfa}
    734 which unrolls a loop N times (N = 8 above) and uses the ©switch© statement to deal with any iterations not a multiple of N.
    735 While efficient, this sort of special purpose usage is questionable:
    736 \begin{quote}
    737 Disgusting, no? But it compiles and runs just fine. I feel a combination of pride and revulsion at this
    738 discovery.~\cite{Duff83}
    739 \end{quote}
    740 \item
    741 It is possible to place the ©default© clause anywhere in the list of labelled clauses for a ©switch© statement, rather than only at the end.
    742 Virtually all programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
    743 The logic for this semantics is that after checking all the ©case© clauses without success, the ©default© clause is selected;
    744 hence, physically placing the ©default© clause at the end of the ©case© clause list matches with this semantics.
    745 This physical placement can be compared to the physical placement of an ©else© clause at the end of a series of connected ©if©/©else© statements.
    746 
    747 \item
    748 It is possible to place unreachable code at the start of a ©switch© statement, as in:
    749 \begin{cfa}
    750 switch ( x ) {
    751         ®int y = 1;®                            §\C{// unreachable initialization}§
    752         ®x = 7;®                                        §\C{// unreachable code without label/branch}§
    753   case 0: ...
    754         ...
    755         ®int z = 0;®                            §\C{// unreachable initialization, cannot appear after case}§
    756         z = 2;
    757   case 1:
    758         ®x = z;®                                        §\C{// without fall through, z is uninitialized}§
    759 }
    760 \end{cfa}
    761 While 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.
    762 Furthermore, any statements before the first ©case© clause can only be executed if labelled and transferred to using a ©goto©, either from outside or inside of the ©switch©, both of which are problematic.
    763 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.
    764 The key observation is that the ©switch© statement branches into control structure, \ie there are multiple entry points into its statement body.
    765 \end{enumerate}
    766 
    767 Before discussing potential language changes to deal with these problems, it is worth observing that in a typical C program:
    768 \begin{itemize}
    769 \item
    770 the number of ©switch© statements is small,
    771 \item
    772 most ©switch© statements are well formed (\ie no \Index*{Duff's device}),
    773 \item
    774 the ©default© clause is usually written as the last case-clause,
    775 \item
    776 and there is only a medium amount of fall-through from one ©case© clause to the next, and most of these result from a list of case values executing common code, rather than a sequence of case actions that compound.
    777 \end{itemize}
    778 These observations put into perspective the \CFA changes to the ©switch©.
    779 \begin{enumerate}
    780 \item
    781 Eliminating default fall-through has the greatest potential for affecting existing code.
    782 However, even if fall-through is removed, most ©switch© statements would continue to work because of the explicit transfers already present at the end of each ©case© clause, the common placement of the ©default© clause at the end of the case list, and the most common use of fall-through, \ie a list of ©case© clauses executing common code, \eg:
    783 \begin{cfa}
    784 case 1:  case 2:  case 3: ...
    785 \end{cfa}
    786 still works.
    787 Nevertheless, reversing the default action would have a non-trivial effect on case actions that compound, such as the above example of processing shell arguments.
    788 Therefore, 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:
    789 \begin{cfa}
    790 ®choose® ( i ) {
    791   case 1:  case 2:  case 3:
    792         ...
    793         ®// implicit end of switch (break)
    794   ®case 5:
    795         ...
    796         ®fallthru®;                                     §\C{// explicit fall through}§
    797   case 7:
    798         ...
    799         ®break®                                         §\C{// explicit end of switch (redundant)}§
    800   default:
    801         j = 3;
    802 }
    803 \end{cfa}
    804 Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses;
    805 An implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.
    806 An 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.
    807 As well, allowing an explicit ©break© from the ©choose© is a carry over from the ©switch© statement, and expected by C programmers.
    808 \item
    809 \Index*{Duff's device} is eliminated from both ©switch© and ©choose© statements, and only invalidates a small amount of very questionable code.
    810 Hence, the ©case© clause must appear at the same nesting level as the ©switch©/©choose© body, as is done in most other programming languages with ©switch© statements.
    811 \item
    812 The issue of ©default© at locations other than at the end of the cause clause can be solved by using good programming style, and there are a few reasonable situations involving fall-through where the ©default© clause needs to appear is locations other than at the end.
    813 Therefore, no change is made for this issue.
    814 \item
    815 Dealing with unreachable code in a ©switch©/©choose© body is solved by restricting declarations and associated initialization to the start of statement body, which is executed \emph{before} the transfer to the appropriate ©case© clause\footnote{
    816 Essentially, these declarations are hoisted before the ©switch©/©choose© statement and both declarations and statement are surrounded by a compound statement.} and precluding statements before the first ©case© clause.
    817 Further declarations at the same nesting level as the statement body are disallowed to ensure every transfer into the body is sound.
    818 \begin{cfa}
    819 switch ( x ) {
    820         ®int i = 0;®                            §\C{// allowed only at start}§
    821   case 0:
    822         ...
    823         ®int j = 0;®                            §\C{// disallowed}§
    824   case 1:
    825         {
    826                 ®int k = 0;®                    §\C{// allowed at different nesting levels}§
    827                 ...
    828           ®case 2:®                                     §\C{// disallow case in nested statements}§
    829         }
    830   ...
    831 }
    832 \end{cfa}
    833 \end{enumerate}
    834 
    835 
    836 \section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}}
    837 
    838 C restricts the ©case© clause of a ©switch© statement to a single value.
    839 For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values.
    840 Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C.
    841 Therefore, the ©case© clause is extended with a list of values, as in:
    842 \begin{cquote}
    843 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    844 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
    845 \begin{cfa}
    846 switch ( i ) {
    847   case ®1, 3, 5®:
    848         ...
    849   case ®2, 4, 6®:
    850         ...
    851 }
    852 \end{cfa}
    853 &
    854 \begin{cfa}
    855 switch ( i ) {
    856   case 1: case 3 : case 5:
    857         ...
    858   case 2: case 4 : case 6:
    859         ...
    860 }
    861 \end{cfa}
    862 &
    863 \begin{cfa}
    864 
    865 // odd values
    866 
    867 // even values
    868 
    869 
    870 \end{cfa}
    871 \end{tabular}
    872 \end{cquote}
    873 In addition, subranges are allowed to specify case values.\footnote{
    874 gcc has the same mechanism but awkward syntax, \lstinline@2 ...42@, because a space is required after a number, otherwise the period is a decimal point.}
    875 \begin{cfa}
    876 switch ( i ) {
    877   case ®1~5:®                                   §\C{// 1, 2, 3, 4, 5}§
    878         ...
    879   case ®10~15:®                                 §\C{// 10, 11, 12, 13, 14, 15}§
    880         ...
    881 }
    882 \end{cfa}
    883 Lists of subranges are also allowed.
    884 \begin{cfa}
    885 case ®1~5, 12~21, 35~42®:
    886 \end{cfa}
    887 
    888 
    889 \section{\texorpdfstring{\protect\lstinline@with@ Statement}{with Statement}}
     1145Otherwise, the implicit targets of the current ©continue© and ©break©, \ie the closest enclosing loop or ©switch©, change as certain constructs are added or removed.
     1146
     1147
     1148%\section{\texorpdfstring{\protect\lstinline@with@ Statement}{with Statement}}
     1149\section{\texorpdfstring{\LstKeywordStyle{with} Statement}{with Statement}}
    8901150\label{s:WithStatement}
    8911151
    8921152Grouping 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:
    8931153\begin{cfa}
    894 struct S {                                                                      §\C{// aggregate}§
    895         char c;                                                                 §\C{// fields}§
     1154struct S { §\C{// aggregate}§
     1155        char c; §\C{// fields}§
    8961156        int i;
    8971157        double d;
     
    9021162\begin{cfa}
    9031163void f( S s ) {
    904         `s.`c; `s.`i; `s.`d;                                    §\C{// access containing fields}§
     1164        ®s.®c; ®s.®i; ®s.®d; §\C{// access containing fields}§
    9051165}
    9061166\end{cfa}
     
    9091169\begin{C++}
    9101170struct S {
    911         char c;                                                                 §\C{// fields}§
     1171        char c; §\C{// fields}§
    9121172        int i;
    9131173        double d;
    914         void f() {                                                              §\C{// implicit ``this'' aggregate}§
    915                 `this->`c; `this->`i; `this->`d;        §\C{// access containing fields}§
     1174        void f() { §\C{// implicit ``this'' aggregate}§
     1175                ®this->®c; ®this->®i; ®this->®d; §\C{// access containing fields}§
    9161176        }
    9171177}
    9181178\end{C++}
    919 Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]$this->$ because of lexical scoping.
     1179Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping.
    9201180However, for other aggregate parameters, qualification is necessary:
    9211181\begin{cfa}
    9221182struct T { double m, n; };
    923 int S::f( T & t ) {                                                     §\C{// multiple aggregate parameters}§
    924         c; i; d;                                                                §\C{\color{red}// this--{\textgreater}.c, this--{\textgreater}.i, this--{\textgreater}.d}§
    925         `t.`m; `t.`n;                                                   §\C{// must qualify}§
    926 }
    927 \end{cfa}
    928 
    929 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.
     1183int S::f( T & t ) { §\C{// multiple aggregate parameters}§
     1184        c; i; d; §\C{\color{red}// this--{\textgreater}.c, this--{\textgreater}.i, this--{\textgreater}.d}§
     1185        ®t.®m; ®t.®n; §\C{// must qualify}§
     1186}
     1187\end{cfa}
     1188
     1189To 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.
    9301190Hence, the qualified fields become variables with the side-effect that it is easier to optimizing field references in a block.
    9311191\begin{cfa}
    932 void f( S & this ) `with ( this )` {            §\C{// with statement}§
    933         c; i; d;                                                                §\C{\color{red}// this.c, this.i, this.d}§
     1192void f( S & this ) ®with ( this )® { §\C{// with statement}§
     1193        c; i; d; §\C{\color{red}// this.c, this.i, this.d}§
    9341194}
    9351195\end{cfa}
    9361196with the generality of opening multiple aggregate-parameters:
    9371197\begin{cfa}
    938 void f( S & s, T & t ) `with ( s, t )` {                §\C{// multiple aggregate parameters}§
    939         c; i; d;                                                                §\C{\color{red}// s.c, s.i, s.d}§
    940         m; n;                                                                   §\C{\color{red}// t.m, t.n}§
    941 }
    942 \end{cfa}
    943 
    944 In detail, the @with@ statement has the form:
     1198void f( S & s, T & t ) ®with ( s, t )® { §\C{// multiple aggregate parameters}§
     1199        c; i; d; §\C{\color{red}// s.c, s.i, s.d}§
     1200        m; n; §\C{\color{red}// t.m, t.n}§
     1201}
     1202\end{cfa}
     1203
     1204In detail, the ©with© statement has the form:
    9451205\begin{cfa}
    9461206§\emph{with-statement}§:
     
    9571217The difference between parallel and nesting occurs for fields with the same name and type:
    9581218\begin{cfa}
    959 struct S { int `i`; int j; double m; } s, w;
    960 struct T { int `i`; int k; int m; } t, w;
     1219struct S { int ®i®; int j; double m; } s, w;
     1220struct T { int ®i®; int k; int m; } t, w;
    9611221with ( s, t ) {
    962         j + k;                                                                  §\C{// unambiguous, s.j + t.k}§
    963         m = 5.0;                                                                §\C{// unambiguous, t.m = 5.0}§
    964         m = 1;                                                                  §\C{// unambiguous, s.m = 1}§
    965         int a = m;                                                              §\C{// unambiguous, a = s.i }§
    966         double b = m;                                                   §\C{// unambiguous, b = t.m}§
    967         int c = s.i + t.i;                                              §\C{// unambiguous, qualification}§
    968         (double)m;                                                              §\C{// unambiguous, cast}§
    969 }
    970 \end{cfa}
    971 For parallel semantics, both @s.i@ and @t.i@ are visible, so @i@ is ambiguous without qualification;
    972 for nested semantics, @t.i@ hides @s.i@, so @i@ implies @t.i@.
     1222        j + k; §\C{// unambiguous, s.j + t.k}§
     1223        m = 5.0; §\C{// unambiguous, t.m = 5.0}§
     1224        m = 1; §\C{// unambiguous, s.m = 1}§
     1225        int a = m; §\C{// unambiguous, a = s.i }§
     1226        double b = m; §\C{// unambiguous, b = t.m}§
     1227        int c = s.i + t.i; §\C{// unambiguous, qualification}§
     1228        (double)m; §\C{// unambiguous, cast}§
     1229}
     1230\end{cfa}
     1231For parallel semantics, both ©s.i© and ©t.i© are visible, so ©i© is ambiguous without qualification;
     1232for nested semantics, ©t.i© hides ©s.i©, so ©i© implies ©t.i©.
    9731233\CFA's ability to overload variables means fields with the same name but different types are automatically disambiguated, eliminating most qualification when opening multiple aggregates.
    9741234Qualification or a cast is used to disambiguate.
    9751235
    976 There is an interesting problem between parameters and the function-body @with@, \eg:
    977 \begin{cfa}
    978 void ?{}( S & s, int i ) with ( s ) {           §\C{// constructor}§
    979         `s.i = i;`  j = 3;  m = 5.5;                    §\C{// initialize fields}§
    980 }
    981 \end{cfa}
    982 Here, the assignment @s.i = i@ means @s.i = s.i@, which is meaningless, and there is no mechanism to qualify the parameter @i@, making the assignment impossible using the function-body @with@.
     1236There is an interesting problem between parameters and the function-body ©with©, \eg:
     1237\begin{cfa}
     1238void ?{}( S & s, int i ) with ( s ) { §\C{// constructor}§
     1239        ®s.i = i;®  j = 3;  m = 5.5; §\C{// initialize fields}§
     1240}
     1241\end{cfa}
     1242Here, the assignment ©s.i = i© means ©s.i = s.i©, which is meaningless, and there is no mechanism to qualify the parameter ©i©, making the assignment impossible using the function-body ©with©.
    9831243To solve this problem, parameters are treated like an initialized aggregate:
    9841244\begin{cfa}
     
    9901250and implicitly opened \emph{after} a function-body open, to give them higher priority:
    9911251\begin{cfa}
    992 void ?{}( S & s, int `i` ) with ( s ) `with( §\emph{\color{red}params}§ )` {
    993         s.i = `i`; j = 3; m = 5.5;
    994 }
    995 \end{cfa}
    996 Finally, a cast may be used to disambiguate among overload variables in a @with@ expression:
    997 \begin{cfa}
    998 with ( w ) { ... }                                                      §\C{// ambiguous, same name and no context}§
    999 with ( (S)w ) { ... }                                           §\C{// unambiguous, cast}§
    1000 \end{cfa}
    1001 and @with@ expressions may be complex expressions with type reference (see Section~\ref{s:References}) to aggregate:
     1252void ?{}( S & s, int ®i® ) with ( s ) ®with( §\emph{\color{red}params}§ )® {
     1253        s.i = ®i®; j = 3; m = 5.5;
     1254}
     1255\end{cfa}
     1256Finally, a cast may be used to disambiguate among overload variables in a ©with© expression:
     1257\begin{cfa}
     1258with ( w ) { ... } §\C{// ambiguous, same name and no context}§
     1259with ( (S)w ) { ... } §\C{// unambiguous, cast}§
     1260\end{cfa}
     1261and ©with© expressions may be complex expressions with type reference (see Section~\ref{s:References}) to aggregate:
    10021262% \begin{cfa}
    10031263% struct S { int i, j; } sv;
    1004 % with ( sv ) {                                                         §\C{// implicit reference}§
     1264% with ( sv ) { §\C{// implicit reference}§
    10051265%       S & sr = sv;
    1006 %       with ( sr ) {                                                   §\C{// explicit reference}§
     1266%       with ( sr ) { §\C{// explicit reference}§
    10071267%               S * sp = &sv;
    1008 %               with ( *sp ) {                                          §\C{// computed reference}§
    1009 %                       i = 3; j = 4;                                   §\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}§
     1268%               with ( *sp ) { §\C{// computed reference}§
     1269%                       i = 3; j = 4; §\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}§
    10101270%               }
    1011 %               i = 2; j = 3;                                           §\C{\color{red}// sr.i, sr.j}§
     1271%               i = 2; j = 3; §\C{\color{red}// sr.i, sr.j}§
    10121272%       }
    1013 %       i = 1; j = 2;                                                   §\C{\color{red}// sv.i, sv.j}§
     1273%       i = 1; j = 2; §\C{\color{red}// sv.i, sv.j}§
    10141274% }
    10151275% \end{cfa}
     
    10191279class C {
    10201280        int i, j;
    1021         int mem() {                                     §\C{\color{red}// implicit "this" parameter}§
    1022                 i = 1;                                  §\C{\color{red}// this->i}§
    1023                 j = 2;                                  §\C{\color{red}// this->j}§
     1281        int mem() { §\C{\color{red}// implicit "this" parameter}§
     1282                i = 1; §\C{\color{red}// this->i}§
     1283                j = 2; §\C{\color{red}// this->j}§
    10241284        }
    10251285}
     
    10281288\begin{cfa}
    10291289struct S { int i, j; };
    1030 int mem( S & ®this® ) {                 §\C{// explicit "this" parameter}§
    1031         ®this.®i = 1;                           §\C{// "this" is not elided}§
     1290int mem( S & ®this® ) { §\C{// explicit "this" parameter}§
     1291        ®this.®i = 1; §\C{// "this" is not elided}§
    10321292        ®this.®j = 2;
    10331293}
     
    10381298\begin{cfa}
    10391299int mem( S & this ) ®with( this )® { §\C{// with clause}§
    1040         i = 1;                                          §\C{\color{red}// this.i}§
    1041         j = 2;                                          §\C{\color{red}// this.j}§
     1300        i = 1; §\C{\color{red}// this.i}§
     1301        j = 2; §\C{\color{red}// this.j}§
    10421302}
    10431303\end{cfa}
     
    10561316        struct S1 { ... } s1;
    10571317        struct S2 { ... } s2;
    1058         ®with( s1 )® {                          §\C{// with statement}§
     1318        ®with( s1 )® { §\C{// with statement}§
    10591319                // access fields of s1 without qualification
    1060                 ®with s2® {                             §\C{// nesting}§
     1320                ®with s2® { §\C{// nesting}§
    10611321                        // access fields of s1 and s2 without qualification
    10621322                }
     
    11131373Non-local transfer can cause stack unwinding, \ie non-local routine termination, depending on the kind of raise.
    11141374\begin{cfa}
    1115 exception_t E {};                               §\C{// exception type}§
     1375exception_t E {}; §\C{// exception type}§
    11161376void f(...) {
    1117         ... throw E{}; ...                      §\C{// termination}§
    1118         ... throwResume E{}; ...        §\C{// resumption}§
     1377        ... throw E{}; ... §\C{// termination}§
     1378        ... throwResume E{}; ... §\C{// resumption}§
    11191379}
    11201380try {
    11211381        f(...);
    1122 } catch( E e ; §boolean-predicate§ ) {                  §\C[8cm]{// termination handler}§
     1382} catch( E e ; §boolean-predicate§ ) {          §\C[8cm]{// termination handler}§
    11231383        // recover and continue
    1124 } catchResume( E e ; §boolean-predicate§ ) {    §\C{// resumption handler}\CRT§
     1384} catchResume( E e ; §boolean-predicate§ ) { §\C{// resumption handler}\CRT§
    11251385        // repair and return
    11261386} finally {
     
    11821442For example, a routine returning a \Index{pointer} to an array of integers is defined and used in the following way:
    11831443\begin{cfa}
    1184 int ®(*®f®())[®5®]® {...};                              §\C{// definition}§
    1185  ... ®(*®f®())[®3®]® += 1;                              §\C{// usage}§
     1444int ®(*®f®())[®5®]® {...}; §\C{// definition}§
     1445 ... ®(*®f®())[®3®]® += 1; §\C{// usage}§
    11861446\end{cfa}
    11871447Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}).
    1188 While attempting to make the two contexts consistent is a laudable goal, it has not worked out in practice.
     1448While attempting to make the two contexts consistent is a laudable goal, it has not worked out in practice, even though Dennis Richie believed otherwise:
     1449\begin{quote}
     1450In spite of its difficulties, I believe that the C's approach to declarations remains plausible, and am comfortable with it; it is a useful unifying principle.~\cite[p.~12]{Ritchie93}
     1451\end{quote}
    11891452
    11901453\CFA provides its own type, variable and routine declarations, using a different syntax.
     
    13721635*x = 3;                 // implicit dereference
    13731636int * ®const® y = (int *)104;
    1374 *y = *x;                // implicit dereference
     1637*y = *x;                        // implicit dereference
    13751638\end{cfa}
    13761639\end{tabular}
     
    13861649\hline
    13871650\begin{cfa}
    1388 lda             r1,100  // load address of x
    1389 ld               r2,(r1)          // load value of x
    1390 lda             r3,104  // load address of y
    1391 st               r2,(r3)          // store x into y
     1651lda             r1,100   // load address of x
     1652ld               r2,(r1)   // load value of x
     1653lda             r3,104   // load address of y
     1654st               r2,(r3)   // store x into y
    13921655\end{cfa}
    13931656&
    13941657\begin{cfa}
    13951658
    1396 ld              r2,(100)        // load value of x
    1397 
    1398 st              r2,(104)        // store x into y
     1659ld              r2,(100)   // load value of x
     1660
     1661st              r2,(104)   // store x into y
    13991662\end{cfa}
    14001663\end{tabular}
     
    14101673\begin{cfa}
    14111674int x, y, ®*® p1, ®*® p2, ®**® p3;
    1412 p1 = ®&®x;              // p1 points to x
    1413 p2 = p1;                // p2 points to x
    1414 p1 = ®&®y;              // p1 points to y
    1415 p3 = &p2;               // p3 points to p2
     1675p1 = ®&®x;    // p1 points to x
     1676p2 = p1;    // p2 points to x
     1677p1 = ®&®y;    // p1 points to y
     1678p3 = &p2;  // p3 points to p2
    14161679\end{cfa}
    14171680&
     
    14241687For example, \Index*{Algol68}~\cite{Algol68} infers pointer dereferencing to select the best meaning for each pointer usage
    14251688\begin{cfa}
    1426 p2 = p1 + x;                                    §\C{// compiler infers *p2 = *p1 + x;}§
     1689p2 = p1 + x; §\C{// compiler infers *p2 = *p1 + x;}§
    14271690\end{cfa}
    14281691Algol68 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.
    1429 Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices. 
     1692Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices.
    14301693
    14311694Rather than inferring dereference, most programming languages pick one implicit dereferencing semantics, and the programmer explicitly indicates the other to resolve address-duality.
    14321695In C, objects of pointer type always manipulate the pointer object's address:
    14331696\begin{cfa}
    1434 p1 = p2;                                                §\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}§
    1435 p2 = p1 + x;                                    §\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}§
     1697p1 = p2; §\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}§
     1698p2 = p1 + x; §\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}§
    14361699\end{cfa}
    14371700even though the assignment to ©p2© is likely incorrect, and the programmer probably meant:
    14381701\begin{cfa}
    1439 p1 = p2;                                                §\C{// pointer address assignment}§
    1440 ®*®p2 = ®*®p1 + x;                              §\C{// pointed-to value assignment / operation}§
     1702p1 = p2; §\C{// pointer address assignment}§
     1703®*®p2 = ®*®p1 + x; §\C{// pointed-to value assignment / operation}§
    14411704\end{cfa}
    14421705The 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©).
     
    14551718\begin{cfa}
    14561719int x, y, ®&® r1, ®&® r2, ®&&® r3;
    1457 ®&®r1 = &x;                                             §\C{// r1 points to x}§
    1458 ®&®r2 = &r1;                                    §\C{// r2 points to x}§
    1459 ®&®r1 = &y;                                             §\C{// r1 points to y}§
    1460 ®&&®r3 = ®&®&r2;                                §\C{// r3 points to r2}§
     1720®&®r1 = &x; §\C{// r1 points to x}§
     1721®&®r2 = &r1; §\C{// r2 points to x}§
     1722®&®r1 = &y; §\C{// r1 points to y}§
     1723®&&®r3 = ®&®&r2; §\C{// r3 points to r2}§
    14611724r2 = ((r1 + r2) * (r3 - r1)) / (r3 - 15); §\C{// implicit dereferencing}§
    14621725\end{cfa}
     
    14741737For a \CFA reference type, the cancellation on the left-hand side of assignment leaves the reference as an address (\Index{lvalue}):
    14751738\begin{cfa}
    1476 (&®*®)r1 = &x;                                  §\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}§
     1739(&®*®)r1 = &x; §\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}§
    14771740\end{cfa}
    14781741Similarly, the address of a reference can be obtained for assignment or computation (\Index{rvalue}):
    14791742\begin{cfa}
    1480 (&(&®*®)®*®)r3 = &(&®*®)r2;             §\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}§
     1743(&(&®*®)®*®)r3 = &(&®*®)r2; §\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}§
    14811744\end{cfa}
    14821745Cancellation\index{cancellation!pointer/reference}\index{pointer!cancellation} works to arbitrary depth.
     
    14861749int x, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    14871750                 &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    1488 ***p3 = 3;                                              §\C{// change x}§
    1489 r3 = 3;                                                 §\C{// change x, ***r3}§
    1490 **p3 = ...;                                             §\C{// change p1}§
    1491 &r3 = ...;                                              §\C{// change r1, (\&*)**r3, 1 cancellation}§
    1492 *p3 = ...;                                              §\C{// change p2}§
    1493 &&r3 = ...;                                             §\C{// change r2, (\&(\&*)*)*r3, 2 cancellations}§
    1494 &&&r3 = p3;                                             §\C{// change r3 to p3, (\&(\&(\&*)*)*)r3, 3 cancellations}§
     1751***p3 = 3; §\C{// change x}§
     1752r3 = 3; §\C{// change x, ***r3}§
     1753**p3 = ...; §\C{// change p1}§
     1754&r3 = ...; §\C{// change r1, (\&*)**r3, 1 cancellation}§
     1755*p3 = ...; §\C{// change p2}§
     1756&&r3 = ...; §\C{// change r2, (\&(\&*)*)*r3, 2 cancellations}§
     1757&&&r3 = p3; §\C{// change r3 to p3, (\&(\&(\&*)*)*)r3, 3 cancellations}§
    14951758\end{cfa}
    14961759Furthermore, both types are equally performant, as the same amount of dereferencing occurs for both types.
     
    14991762As for a pointer type, a reference type may have qualifiers:
    15001763\begin{cfa}
    1501 const int cx = 5;                                       §\C{// cannot change cx;}§
    1502 const int & cr = cx;                            §\C{// cannot change what cr points to}§
    1503 ®&®cr = &cx;                                            §\C{// can change cr}§
    1504 cr = 7;                                                         §\C{// error, cannot change cx}§
    1505 int & const rc = x;                                     §\C{// must be initialized}§
    1506 ®&®rc = &x;                                                     §\C{// error, cannot change rc}§
    1507 const int & const crc = cx;                     §\C{// must be initialized}§
    1508 crc = 7;                                                        §\C{// error, cannot change cx}§
    1509 ®&®crc = &cx;                                           §\C{// error, cannot change crc}§
     1764const int cx = 5; §\C{// cannot change cx;}§
     1765const int & cr = cx; §\C{// cannot change what cr points to}§
     1766®&®cr = &cx; §\C{// can change cr}§
     1767cr = 7; §\C{// error, cannot change cx}§
     1768int & const rc = x; §\C{// must be initialized}§
     1769®&®rc = &x; §\C{// error, cannot change rc}§
     1770const int & const crc = cx; §\C{// must be initialized}§
     1771crc = 7; §\C{// error, cannot change cx}§
     1772®&®crc = &cx; §\C{// error, cannot change crc}§
    15101773\end{cfa}
    15111774Hence, 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}:
    15121775\begin{cfa}
    1513 int & const cr = *0;                            §\C{// where 0 is the int * zero}§
     1776int & const cr = *0; §\C{// where 0 is the int * zero}§
    15141777\end{cfa}
    15151778Note, constant reference-types do not prevent \Index{addressing errors} because of explicit storage-management:
     
    15181781cr = 5;
    15191782free( &cr );
    1520 cr = 7;                                                         §\C{// unsound pointer dereference}§
     1783cr = 7; §\C{// unsound pointer dereference}§
    15211784\end{cfa}
    15221785
     
    15431806\begin{cfa}
    15441807int w, x, y, z, & ar[3] = { x, y, z }; §\C{// initialize array of references}§
    1545 &ar[1] = &w;                                            §\C{// change reference array element}§
    1546 typeof( ar[1] ) p;                                      §\C{// (gcc) is int, \ie the type of referenced object}§
    1547 typeof( &ar[1] ) q;                                     §\C{// (gcc) is int \&, \ie the type of reference}§
    1548 sizeof( ar[1] ) == sizeof( int );       §\C{// is true, \ie the size of referenced object}§
    1549 sizeof( &ar[1] ) == sizeof( int *)      §\C{// is true, \ie the size of a reference}§
     1808&ar[1] = &w; §\C{// change reference array element}§
     1809typeof( ar[1] ) p; §\C{// (gcc) is int, \ie the type of referenced object}§
     1810typeof( &ar[1] ) q; §\C{// (gcc) is int \&, \ie the type of reference}§
     1811sizeof( ar[1] ) == sizeof( int ); §\C{// is true, \ie the size of referenced object}§
     1812sizeof( &ar[1] ) == sizeof( int *) §\C{// is true, \ie the size of a reference}§
    15501813\end{cfa}
    15511814
     
    15641827Therefore, for pointer/reference initialization, the initializing value must be an address not a value.
    15651828\begin{cfa}
    1566 int * p = &x;                                           §\C{// assign address of x}§
    1567 ®int * p = x;®                                          §\C{// assign value of x}§
    1568 int & r = x;                                            §\C{// must have address of x}§
     1829int * p = &x; §\C{// assign address of x}§
     1830®int * p = x;® §\C{// assign value of x}§
     1831int & r = x; §\C{// must have address of x}§
    15691832\end{cfa}
    15701833Like 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).
     
    15751838Similarly, 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.
    15761839\begin{cfa}
    1577 int & f( int & r );                                     §\C{// reference parameter and return}§
    1578 z = f( x ) + f( y );                            §\C{// reference operator added, temporaries needed for call results}§
     1840int & f( int & r ); §\C{// reference parameter and return}§
     1841z = f( x ) + f( y ); §\C{// reference operator added, temporaries needed for call results}§
    15791842\end{cfa}
    15801843Within routine ©f©, it is possible to change the argument by changing the corresponding parameter, and parameter ©r© can be locally reassigned within ©f©.
     
    16031866void f( int & r );
    16041867void g( int * p );
    1605 f( 3 );                   g( ®&®3 );            §\C{// compiler implicit generates temporaries}§
    1606 f( x + y );             g( ®&®(x + y) );        §\C{// compiler implicit generates temporaries}§
     1868f( 3 );                   g( ®&®3 ); §\C{// compiler implicit generates temporaries}§
     1869f( x + y );             g( ®&®(x + y) ); §\C{// compiler implicit generates temporaries}§
    16071870\end{cfa}
    16081871Essentially, there is an implicit \Index{rvalue} to \Index{lvalue} conversion in this case.\footnote{
     
    16151878\begin{cfa}
    16161879void f( int i );
    1617 void (* fp)( int );                                     §\C{// routine pointer}§
    1618 fp = f;                                                         §\C{// reference initialization}§
    1619 fp = &f;                                                        §\C{// pointer initialization}§
    1620 fp = *f;                                                        §\C{// reference initialization}§
    1621 fp(3);                                                          §\C{// reference invocation}§
    1622 (*fp)(3);                                                       §\C{// pointer invocation}§
     1880void (* fp)( int ); §\C{// routine pointer}§
     1881fp = f; §\C{// reference initialization}§
     1882fp = &f; §\C{// pointer initialization}§
     1883fp = *f; §\C{// reference initialization}§
     1884fp(3); §\C{// reference invocation}§
     1885(*fp)(3); §\C{// pointer invocation}§
    16231886\end{cfa}
    16241887While 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.
    16251888Instead, a routine object should be referenced by a ©const© reference:
    16261889\begin{cfa}
    1627 ®const® void (®&® fr)( int ) = f;       §\C{// routine reference}§
    1628 fr = ...                                                        §\C{// error, cannot change code}§
    1629 &fr = ...;                                                      §\C{// changing routine reference}§
    1630 fr( 3 );                                                        §\C{// reference call to f}§
    1631 (*fr)(3);                                                       §\C{// error, incorrect type}§
     1890®const® void (®&® fr)( int ) = f; §\C{// routine reference}§
     1891fr = ... §\C{// error, cannot change code}§
     1892&fr = ...; §\C{// changing routine reference}§
     1893fr( 3 ); §\C{// reference call to f}§
     1894(*fr)(3); §\C{// error, incorrect type}§
    16321895\end{cfa}
    16331896because the value of the routine object is a routine literal, \ie the routine code is normally immutable during execution.\footnote{
     
    16421905\begin{itemize}
    16431906\item
    1644 if ©R© is an \Index{rvalue} of type ©T &$_1$...&$_r$© where $r \ge 1$ references (©&© symbols) then ©&R© has type ©T ®*®&$_{\color{red}2}$...&$_{\color{red}r}$©, \ie ©T© pointer with $r-1$ references (©&© symbols).
    1645 
    1646 \item
    1647 if ©L© is an \Index{lvalue} of type ©T &$_1$...&$_l$© where $l \ge 0$ references (©&© symbols) then ©&L© has type ©T ®*®&$_{\color{red}1}$...&$_{\color{red}l}$©, \ie ©T© pointer with $l$ references (©&© symbols).
     1907if ©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).
     1908
     1909\item
     1910if ©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).
    16481911\end{itemize}
    16491912The following example shows the first rule applied to different \Index{rvalue} contexts:
     
    16511914int x, * px, ** ppx, *** pppx, **** ppppx;
    16521915int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    1653 x = rrrx;               // rrrx is an lvalue with type int &&& (equivalent to x)
    1654 px = &rrrx;             // starting from rrrx, &rrrx is an rvalue with type int *&&& (&x)
    1655 ppx = &&rrrx;   // starting from &rrrx, &&rrrx is an rvalue with type int **&& (&rx)
    1656 pppx = &&&rrrx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (&rrx)
    1657 ppppx = &&&&rrrx; // starting from &&&rrrx, &&&&rrrx is an rvalue with type int **** (&rrrx)
     1916x = rrrx; §\C[2.0in]{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}§
     1917px = &rrrx; §\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (\&x)}§
     1918ppx = &&rrrx; §\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (\&rx)}§
     1919pppx = &&&rrrx; §\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (\&rrx)}§
     1920ppppx = &&&&rrrx; §\C{// starting from \&\&\&rrrx, \&\&\&\&rrrx is an rvalue with type int **** (\&rrrx)}§
    16581921\end{cfa}
    16591922The following example shows the second rule applied to different \Index{lvalue} contexts:
     
    16611924int x, * px, ** ppx, *** pppx;
    16621925int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    1663 rrrx = 2;               // rrrx is an lvalue with type int &&& (equivalent to x)
    1664 &rrrx = px;             // starting from rrrx, &rrrx is an rvalue with type int *&&& (rx)
    1665 &&rrrx = ppx;   // starting from &rrrx, &&rrrx is an rvalue with type int **&& (rrx)
    1666 &&&rrrx = pppx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (rrrx)
     1926rrrx = 2; §\C{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}§
     1927&rrrx = px; §\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (rx)}§
     1928&&rrrx = ppx; §\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (rrx)}§
     1929&&&rrrx = pppx; §\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (rrrx)}\CRT§
    16671930\end{cfa}
    16681931
     
    16771940\begin{cfa}
    16781941int x;
    1679 x + 1;                  // lvalue variable (int) converts to rvalue for expression
     1942x + 1; §\C[2.0in]{// lvalue variable (int) converts to rvalue for expression}§
    16801943\end{cfa}
    16811944An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped.
     
    16871950\begin{cfa}
    16881951int x, &r = x, f( int p );
    1689 x = ®r® + f( ®r® );  // lvalue reference converts to rvalue
     1952x = ®r® + f( ®r® ); §\C{// lvalue reference converts to rvalue}§
    16901953\end{cfa}
    16911954An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped.
     
    16941957lvalue to reference conversion: \lstinline[deletekeywords=lvalue]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
    16951958\begin{cfa}
    1696 int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &)
    1697 f( ®x® );               // lvalue variable (int) convert to reference (int &)
     1959int x, &r = ®x®, f( int & p ); §\C{// lvalue variable (int) convert to reference (int \&)}§
     1960f( ®x® ); §\C{// lvalue variable (int) convert to reference (int \&)}§
    16981961\end{cfa}
    16991962Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.
     
    17051968\begin{cfa}
    17061969int x, & f( int & p );
    1707 f( ®x + 3® );   // rvalue parameter (int) implicitly converts to lvalue temporary reference (int &)
    1708 ®&f®(...) = &x; // rvalue result (int &) implicitly converts to lvalue temporary reference (int &)
     1970f( ®x + 3® );   §\C[1.5in]{// rvalue parameter (int) implicitly converts to lvalue temporary reference (int \&)}§
     1971®&f®(...) = &x; §\C{// rvalue result (int \&) implicitly converts to lvalue temporary reference (int \&)}\CRT§
    17091972\end{cfa}
    17101973In both case, modifications to the temporary are inaccessible (\Index{warning}).
     
    18952158in 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:
    18962159\begin{cfa}
    1897 [§\,§] g();                                                     §\C{// no input or output parameters}§
    1898 [ void ] g( void );                                     §\C{// no input or output parameters}§
     2160[§\,§] g(); §\C{// no input or output parameters}§
     2161[ void ] g( void ); §\C{// no input or output parameters}§
    18992162\end{cfa}
    19002163
     
    19142177\begin{cfa}
    19152178typedef int foo;
    1916 int f( int (* foo) );                           §\C{// foo is redefined as a parameter name}§
     2179int f( int (* foo) ); §\C{// foo is redefined as a parameter name}§
    19172180\end{cfa}
    19182181The 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.
     
    19222185C-style declarations can be used to declare parameters for \CFA style routine definitions, \eg:
    19232186\begin{cfa}
    1924 [ int ] f( * int, int * );                      §\C{// returns an integer, accepts 2 pointers to integers}§
    1925 [ * int, int * ] f( int );                      §\C{// returns 2 pointers to integers, accepts an integer}§
     2187[ int ] f( * int, int * ); §\C{// returns an integer, accepts 2 pointers to integers}§
     2188[ * int, int * ] f( int ); §\C{// returns 2 pointers to integers, accepts an integer}§
    19262189\end{cfa}
    19272190The 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:
    19282191\begin{cfa}
    19292192#define ptoa( n, d ) int (*n)[ d ]
    1930 int f( ptoa( p, 5 ) ) ...                       §\C{// expands to int f( int (*p)[ 5 ] )}§
    1931 [ int ] f( ptoa( p, 5 ) ) ...           §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§
     2193int f( ptoa( p, 5 ) ) ... §\C{// expands to int f( int (*p)[ 5 ] )}§
     2194[ int ] f( ptoa( p, 5 ) ) ... §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§
    19322195\end{cfa}
    19332196Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    19512214        int z;
    19522215        ... x = 0; ... y = z; ...
    1953         ®return;®                                                       §\C{// implicitly return x, y}§
     2216        ®return;® §\C{// implicitly return x, y}§
    19542217}
    19552218\end{cfa}
     
    19612224[ int x, int y ] f() {
    19622225        ...
    1963 }                                                                               §\C{// implicitly return x, y}§
     2226} §\C{// implicitly return x, y}§
    19642227\end{cfa}
    19652228In this case, the current values of ©x© and ©y© are returned to the calling routine just as if a ©return© had been encountered.
     
    19702233[ int x, int y ] f( int, x, int y ) {
    19712234        ...
    1972 }                                                                               §\C{// implicitly return x, y}§
     2235} §\C{// implicitly return x, y}§
    19732236\end{cfa}
    19742237This notation allows the compiler to eliminate temporary variables in nested routine calls.
    19752238\begin{cfa}
    1976 [ int x, int y ] f( int, x, int y );    §\C{// prototype declaration}§
     2239[ int x, int y ] f( int, x, int y ); §\C{// prototype declaration}§
    19772240int a, b;
    19782241[a, b] = f( f( f( a, b ) ) );
     
    19882251as well, parameter names are optional, \eg:
    19892252\begin{cfa}
    1990 [ int x ] f ();                                                 §\C{// returning int with no parameters}§
    1991 [ * int ] g (int y);                                    §\C{// returning pointer to int with int parameter}§
    1992 [ ] h ( int, char );                                    §\C{// returning no result with int and char parameters}§
    1993 [ * int, int ] j ( int );                               §\C{// returning pointer to int and int, with int parameter}§
     2253[ int x ] f (); §\C{// returning int with no parameters}§
     2254[ * int ] g (int y); §\C{// returning pointer to int with int parameter}§
     2255[ ] h ( int, char ); §\C{// returning no result with int and char parameters}§
     2256[ * int, int ] j ( int ); §\C{// returning pointer to int and int, with int parameter}§
    19942257\end{cfa}
    19952258This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
     
    20122275The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg:
    20132276\begin{cfa}
    2014 * [ int x ] () fp;                                              §\C{// pointer to routine returning int with no parameters}§
    2015 * [ * int ] (int y) gp;                                 §\C{// pointer to routine returning pointer to int with int parameter}§
    2016 * [ ] (int,char) hp;                                    §\C{// pointer to routine returning no result with int and char parameters}§
    2017 * [ * int,int ] ( int ) jp;                             §\C{// pointer to routine returning pointer to int and int, with int parameter}§
     2277* [ int x ] () fp; §\C{// pointer to routine returning int with no parameters}§
     2278* [ * int ] (int y) gp; §\C{// pointer to routine returning pointer to int with int parameter}§
     2279* [ ] (int,char) hp; §\C{// pointer to routine returning no result with int and char parameters}§
     2280* [ * int,int ] ( int ) jp; §\C{// pointer to routine returning pointer to int and int, with int parameter}§
    20182281\end{cfa}
    20192282While parameter names are optional, \emph{a routine name cannot be specified};
    20202283for example, the following is incorrect:
    20212284\begin{cfa}
    2022 * [ int x ] f () fp;                                    §\C{// routine name "f" is not allowed}§
     2285* [ int x ] f () fp; §\C{// routine name "f" is not allowed}§
    20232286\end{cfa}
    20242287
     
    20432306whereas a named (keyword) call may be:
    20442307\begin{cfa}
    2045 p( z : 3, x : 4, y : 7 );       §\C{// rewrite $\Rightarrow$ p( 4, 7, 3 )}§
     2308p( z : 3, x : 4, y : 7 );  §\C{// rewrite $\Rightarrow$ p( 4, 7, 3 )}§
    20462309\end{cfa}
    20472310Here the order of the arguments is unimportant, and the names of the parameters are used to associate argument values with the corresponding parameters.
     
    20602323For example, the following routine prototypes and definition are all valid.
    20612324\begin{cfa}
    2062 void p( int, int, int );                        §\C{// equivalent prototypes}§
     2325void p( int, int, int ); §\C{// equivalent prototypes}§
    20632326void p( int x, int y, int z );
    20642327void p( int y, int x, int z );
    20652328void p( int z, int y, int x );
    2066 void p( int q, int r, int s ) {}        §\C{// match with this definition}§
     2329void p( int q, int r, int s ) {} §\C{// match with this definition}§
    20672330\end{cfa}
    20682331Forcing matching parameter names in routine prototypes with corresponding routine definitions is possible, but goes against a strong tradition in C programming.
     
    20762339int f( int x, double y );
    20772340
    2078 f( j : 3, i : 4 );                              §\C{// 1st f}§
    2079 f( x : 7, y : 8.1 );                    §\C{// 2nd f}§
    2080 f( 4, 5 );                                              §\C{// ambiguous call}§
     2341f( j : 3, i : 4 ); §\C{// 1st f}§
     2342f( x : 7, y : 8.1 ); §\C{// 2nd f}§
     2343f( 4, 5 );  §\C{// ambiguous call}§
    20812344\end{cfa}
    20822345However, named arguments compound routine resolution in conjunction with conversions:
    20832346\begin{cfa}
    2084 f( i : 3, 5.7 );                                §\C{// ambiguous call ?}§
     2347f( i : 3, 5.7 ); §\C{// ambiguous call ?}§
    20852348\end{cfa}
    20862349Depending on the cost associated with named arguments, this call could be resolvable or ambiguous.
     
    20962359the allowable positional calls are:
    20972360\begin{cfa}
    2098 p();                                                    §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
    2099 p( 4 );                                                 §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
    2100 p( 4, 4 );                                              §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
    2101 p( 4, 4, 4 );                                   §\C{// rewrite $\Rightarrow$ p( 4, 4, 4 )}§
     2361p(); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
     2362p( 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     2363p( 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     2364p( 4, 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 4 )}§
    21022365// empty arguments
    2103 p(  , 4, 4 );                                   §\C{// rewrite $\Rightarrow$ p( 1, 4, 4 )}§
    2104 p( 4,  , 4 );                                   §\C{// rewrite $\Rightarrow$ p( 4, 2, 4 )}§
    2105 p( 4, 4,   );                                   §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
    2106 p( 4,  ,   );                                   §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
    2107 p(  , 4,   );                                   §\C{// rewrite $\Rightarrow$ p( 1, 4, 3 )}§
    2108 p(  ,  , 4 );                                   §\C{// rewrite $\Rightarrow$ p( 1, 2, 4 )}§
    2109 p(  ,  ,   );                                   §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
     2366p(  , 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 4 )}§
     2367p( 4,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 4 )}§
     2368p( 4, 4,   ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     2369p( 4,  ,   ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     2370p(  , 4,   ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 3 )}§
     2371p(  ,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 4 )}§
     2372p(  ,  ,   ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
    21102373\end{cfa}
    21112374Here the missing arguments are inserted from the default values in the parameter list.
     
    21312394Default values may only appear in a prototype versus definition context:
    21322395\begin{cfa}
    2133 void p( int x, int y = 2, int z = 3 );          §\C{// prototype: allowed}§
    2134 void p( int, int = 2, int = 3 );                        §\C{// prototype: allowed}§
    2135 void p( int x, int y = 2, int z = 3 ) {}        §\C{// definition: not allowed}§
     2396void p( int x, int y = 2, int z = 3 ); §\C{// prototype: allowed}§
     2397void p( int, int = 2, int = 3 ); §\C{// prototype: allowed}§
     2398void p( int x, int y = 2, int z = 3 ) {} §\C{// definition: not allowed}§
    21362399\end{cfa}
    21372400The reason for this restriction is to allow separate compilation.
     
    21582421\begin{cfa}
    21592422void p( int x, int y = 2, int z = 3... );
    2160 p( 1, 4, 5, 6, z : 3 );         §\C{// assume p( /* positional */, ... , /* named */ );}§
    2161 p( 1, z : 3, 4, 5, 6 );         §\C{// assume p( /* positional */, /* named */, ... );}§
     2423p( 1, 4, 5, 6, z : 3 ); §\C{// assume p( /* positional */, ... , /* named */ );}§
     2424p( 1, z : 3, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, ... );}§
    21622425\end{cfa}
    21632426The first call is an error because arguments 4 and 5 are actually positional not ellipse arguments;
     
    21892452Furthermore, overloading cannot handle accessing default arguments in the middle of a positional list, via a missing argument, such as:
    21902453\begin{cfa}
    2191 p( 1, /* default */, 5 );               §\C{// rewrite $\Rightarrow$ p( 1, 2, 5 )}§
     2454p( 1, /* default */, 5 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 5 )}§
    21922455\end{cfa}
    21932456
     
    22022465\begin{cfa}
    22032466struct {
    2204         int f1;                                 §\C{// named field}§
    2205         int f2 : 4;                             §\C{// named field with bit field size}§
    2206         int : 3;                                §\C{// unnamed field for basic type with bit field size}§
    2207         int ;                                   §\C{// disallowed, unnamed field}§
    2208         int *;                                  §\C{// disallowed, unnamed field}§
    2209         int (*)( int );                 §\C{// disallowed, unnamed field}§
     2467        int f1; §\C{// named field}§
     2468        int f2 : 4; §\C{// named field with bit field size}§
     2469        int : 3; §\C{// unnamed field for basic type with bit field size}§
     2470        int ; §\C{// disallowed, unnamed field}§
     2471        int *; §\C{// disallowed, unnamed field}§
     2472        int (*)( int ); §\C{// disallowed, unnamed field}§
    22102473};
    22112474\end{cfa}
     
    22152478\begin{cfa}
    22162479struct {
    2217         int , , ;                               §\C{// 3 unnamed fields}§
     2480        int , , ; §\C{// 3 unnamed fields}§
    22182481}
    22192482\end{cfa}
     
    22622525        struct T t;
    22632526} s;
    2264        
     2527
    22652528
    22662529
     
    23092572const unsigned int size = 5;
    23102573int ia[size];
    2311 ...                                             §\C{// assign values to array ia}§
    2312 qsort( ia, size );              §\C{// sort ascending order using builtin ?<?}§
     2574... §\C{// assign values to array ia}§
     2575qsort( ia, size ); §\C{// sort ascending order using builtin ?<?}§
    23132576{
    23142577        ®int ?<?( int x, int y ) { return x > y; }® §\C{// nested routine}§
    2315         qsort( ia, size );      §\C{// sort descending order by local redefinition}§
     2578        qsort( ia, size ); §\C{// sort descending order by local redefinition}§
    23162579}
    23172580\end{cfa}
     
    23212584The following program in undefined in \CFA (and Indexc{gcc})
    23222585\begin{cfa}
    2323 [* [int]( int )] foo() {                §\C{// int (* foo())( int )}§
     2586[* [int]( int )] foo() { §\C{// int (* foo())( int )}§
    23242587        int ®i® = 7;
    23252588        int bar( int p ) {
    2326                 ®i® += 1;                               §\C{// dependent on local variable}§
    2327                 sout | ®i® | endl;
     2589                ®i® += 1; §\C{// dependent on local variable}§
     2590                sout | ®i®;
    23282591        }
    2329         return bar;                                     §\C{// undefined because of local dependence}§
     2592        return bar; §\C{// undefined because of local dependence}§
    23302593}
    23312594int main() {
    2332         * [int]( int ) fp = foo();      §\C{// int (* fp)( int )}§
    2333         sout | fp( 3 ) | endl;
    2334 }
    2335 \end{cfa}
    2336 because 
     2595        * [int]( int ) fp = foo(); §\C{// int (* fp)( int )}§
     2596        sout | fp( 3 );
     2597}
     2598\end{cfa}
     2599because
    23372600
    23382601Currently, there are no \Index{lambda} expressions, \ie unnamed routines because routine names are very important to properly select the correct routine.
     
    23432606In C and \CFA, lists of elements appear in several contexts, such as the parameter list of a routine call.
    23442607\begin{cfa}
    2345 f( ®2, x, 3 + i® );                             §\C{// element list}§
     2608f( ®2, x, 3 + i® ); §\C{// element list}§
    23462609\end{cfa}
    23472610A list of elements is called a \newterm{tuple}, and is different from a \Index{comma expression}.
     
    23602623typedef struct { int quot, rem; } div_t;        §\C[7cm]{// from include stdlib.h}§
    23612624div_t div( int num, int den );
    2362 div_t qr = div( 13, 5 );                                        §\C{// return quotient/remainder aggregate}§
    2363 printf( "%d %d\n", qr.quot, qr.rem );           §\C{// print quotient/remainder}§
     2625div_t qr = div( 13, 5 ); §\C{// return quotient/remainder aggregate}§
     2626printf( "%d %d\n", qr.quot, qr.rem ); §\C{// print quotient/remainder}§
    23642627\end{cfa}
    23652628This approach requires a name for the return type and fields, where \Index{naming} is a common programming-language issue.
     
    23712634For example, consider C's \Indexc{modf} function, which returns the integral and fractional part of a floating value.
    23722635\begin{cfa}
    2373 double modf( double x, double * i );            §\C{// from include math.h}§
    2374 double intp, frac = modf( 13.5, &intp );        §\C{// return integral and fractional components}§
    2375 printf( "%g %g\n", intp, frac );                        §\C{// print integral/fractional components}§
     2636double modf( double x, double * i ); §\C{// from include math.h}§
     2637double intp, frac = modf( 13.5, &intp ); §\C{// return integral and fractional components}§
     2638printf( "%g %g\n", intp, frac ); §\C{// print integral/fractional components}§
    23762639\end{cfa}
    23772640This approach requires allocating storage for the return values, which complicates the call site with a sequence of variable declarations leading to the call.
     
    24002663When 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.
    24012664\begin{cfa}
    2402 void g( int, int );                                                     §\C{// 1}§
    2403 void g( double, double );                                       §\C{// 2}§
    2404 g( div( 13, 5 ) );                                                      §\C{// select 1}§
    2405 g( modf( 13.5 ) );                                                      §\C{// select 2}§
     2665void g( int, int ); §\C{// 1}§
     2666void g( double, double ); §\C{// 2}§
     2667g( div( 13, 5 ) ); §\C{// select 1}§
     2668g( modf( 13.5 ) ); §\C{// select 2}§
    24062669\end{cfa}
    24072670In this case, there are two overloaded ©g© routines.
     
    24122675The previous examples can be rewritten passing the multiple returned-values directly to the ©printf© function call.
    24132676\begin{cfa}
    2414 [ int, int ] div( int x, int y );                       §\C{// from include stdlib}§
    2415 printf( "%d %d\n", div( 13, 5 ) );                      §\C{// print quotient/remainder}§
    2416 
    2417 [ double, double ] modf( double x );            §\C{// from include math}§
    2418 printf( "%g %g\n", modf( 13.5 ) );                      §\C{// print integral/fractional components}§
     2677[ int, int ] div( int x, int y ); §\C{// from include stdlib}§
     2678printf( "%d %d\n", div( 13, 5 ) ); §\C{// print quotient/remainder}§
     2679
     2680[ double, double ] modf( double x ); §\C{// from include math}§
     2681printf( "%g %g\n", modf( 13.5 ) ); §\C{// print integral/fractional components}§
    24192682\end{cfa}
    24202683This 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.
     
    24262689\begin{cfa}
    24272690int quot, rem;
    2428 [ quot, rem ] = div( 13, 5 );                           §\C{// assign multiple variables}§
    2429 printf( "%d %d\n", quot, rem );                         §\C{// print quotient/remainder}\CRT§
     2691[ quot, rem ] = div( 13, 5 ); §\C{// assign multiple variables}§
     2692printf( "%d %d\n", quot, rem ); §\C{// print quotient/remainder}\CRT§
    24302693\end{cfa}
    24312694Here, the multiple return-values are matched in much the same way as passing multiple return-values to multiple parameters in a call.
     
    24332696
    24342697\subsection{Expressions}
     2698
     2699% Change order of expression evaluation.
     2700% http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0145r2.pdf
    24352701
    24362702Multiple-return-value functions provide \CFA with a new syntax for expressing a combination of expressions in the return statement and a combination of types in a function signature.
     
    24532719In \CFA, it is possible to overcome this restriction by declaring a \newterm{tuple variable}.
    24542720\begin{cfa}
    2455 [int, int] ®qr® = div( 13, 5 );                 §\C{// initialize tuple variable}§
    2456 printf( "%d %d\n", ®qr® );                              §\C{// print quotient/remainder}§
     2721[int, int] ®qr® = div( 13, 5 ); §\C{// initialize tuple variable}§
     2722printf( "%d %d\n", ®qr® ); §\C{// print quotient/remainder}§
    24572723\end{cfa}
    24582724It is now possible to match the multiple return-values to a single variable, in much the same way as \Index{aggregation}.
     
    24602726One way to access the individual components of a tuple variable is with assignment.
    24612727\begin{cfa}
    2462 [ quot, rem ] = qr;                                             §\C{// assign multiple variables}§
     2728[ quot, rem ] = qr; §\C{// assign multiple variables}§
    24632729\end{cfa}
    24642730
     
    24832749[int, double] * p;
    24842750
    2485 int y = x.0;                                                    §\C{// access int component of x}§
    2486 y = f().1;                                                              §\C{// access int component of f}§
    2487 p->0 = 5;                                                               §\C{// access int component of tuple pointed-to by p}§
    2488 g( x.1, x.0 );                                                  §\C{// rearrange x to pass to g}§
    2489 double z = [ x, f() ].0.1;                              §\C{// access second component of first component of tuple expression}§
     2751int y = x.0; §\C{// access int component of x}§
     2752y = f().1; §\C{// access int component of f}§
     2753p->0 = 5; §\C{// access int component of tuple pointed-to by p}§
     2754g( x.1, x.0 ); §\C{// rearrange x to pass to g}§
     2755double z = [ x, f() ].0.1; §\C{// access second component of first component of tuple expression}§
    24902756\end{cfa}
    24912757Tuple-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.
     
    25542820double y;
    25552821[int, double] z;
    2556 [y, x] = 3.14;                                                  §\C{// mass assignment}§
     2822[y, x] = 3.14; §\C{// mass assignment}§
    25572823[x, y] = z;                                                         §\C{// multiple assignment}§
    25582824z = 10;                                                         §\C{// mass assignment}§
    2559 z = [x, y];                                                             §\C{// multiple assignment}§
     2825z = [x, y]; §\C{// multiple assignment}§
    25602826\end{cfa}
    25612827Let $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.
     
    26012867        double c, d;
    26022868        [ void ] f( [ int, int ] );
    2603         f( [ c, a ] = [ b, d ] = 1.5 );  // assignments in parameter list
     2869        f( [ c, a ] = [ b, d ] = 1.5 ); §\C{// assignments in parameter list}§
    26042870\end{cfa}
    26052871The 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.
     
    26142880\begin{cfa}
    26152881struct S;
    2616 void ?{}(S *);         // (1)
    2617 void ?{}(S *, int);    // (2)
    2618 void ?{}(S * double);  // (3)
    2619 void ?{}(S *, S);      // (4)
    2620 
    2621 [S, S] x = [3, 6.28];  // uses (2), (3), specialized constructors
    2622 [S, S] y;              // uses (1), (1), default constructor
    2623 [S, S] z = x.0;        // uses (4), (4), copy constructor
     2882void ?{}(S *); §\C{// (1)}§
     2883void ?{}(S *, int); §\C{// (2)}§
     2884void ?{}(S * double); §\C{// (3)}§
     2885void ?{}(S *, S); §\C{// (4)}§
     2886
     2887[S, S] x = [3, 6.28]; §\C{// uses (2), (3), specialized constructors}§
     2888[S, S] y; §\C{// uses (1), (1), default constructor}§
     2889[S, S] z = x.0; §\C{// uses (4), (4), copy constructor}§
    26242890\end{cfa}
    26252891In 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)©.
     
    26622928A member-access tuple may be used anywhere a tuple can be used, \eg:
    26632929\begin{cfa}
    2664 s.[ y, z, x ] = [ 3, 3.2, 'x' ];                §\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}§
    2665 f( s.[ y, z ] );                                                §\C{// equivalent to f( s.y, s.z )}§
     2930s.[ y, z, x ] = [ 3, 3.2, 'x' ]; §\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}§
     2931f( s.[ y, z ] ); §\C{// equivalent to f( s.y, s.z )}§
    26662932\end{cfa}
    26672933Note, the fields appearing in a record-field tuple may be specified in any order;
     
    26732939void f( double, long );
    26742940
    2675 f( x.[ 0, 3 ] );                                                §\C{// f( x.0, x.3 )}§
    2676 x.[ 0, 1 ] = x.[ 1, 0 ];                                §\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}§
     2941f( x.[ 0, 3 ] ); §\C{// f( x.0, x.3 )}§
     2942x.[ 0, 1 ] = x.[ 1, 0 ]; §\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}§
    26772943[ long, int, long ] y = x.[ 2, 0, 2 ];
    26782944\end{cfa}
     
    26912957\begin{cfa}
    26922958[ int, float, double ] f();
    2693 [ double, float ] x = f().[ 2, 1 ];             §\C{// f() called once}§
     2959[ double, float ] x = f().[ 2, 1 ]; §\C{// f() called once}§
    26942960\end{cfa}
    26952961
     
    27042970That 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.
    27052971\begin{cfa}
    2706 int f();     // (1)
    2707 double f();  // (2)
    2708 
    2709 f();       // ambiguous - (1),(2) both equally viable
    2710 (int)f();  // choose (2)
     2972int f(); §\C{// (1)}§
     2973double f(); §\C{// (2)}§
     2974
     2975f(); §\C{// ambiguous - (1),(2) both equally viable}§
     2976(int)f(); §\C{// choose (2)}§
    27112977\end{cfa}
    27122978Since casting is a fundamental operation in \CFA, casts need to be given a meaningful interpretation in the context of tuples.
     
    27162982void g();
    27172983
    2718 (void)f();  // valid, ignore results
    2719 (int)g();   // invalid, void cannot be converted to int
     2984(void)f(); §\C{// valid, ignore results}§
     2985(int)g(); §\C{// invalid, void cannot be converted to int}§
    27202986
    27212987struct A { int x; };
    2722 (struct A)f();  // invalid, int cannot be converted to A
     2988(struct A)f(); §\C{// invalid, int cannot be converted to A}§
    27232989\end{cfa}
    27242990In C, line 4 is a valid cast, which calls ©f© and discards its result.
     
    27363002        [int, [int, int], int] g();
    27373003
    2738         ([int, double])f();           // (1) valid
    2739         ([int, int, int])g();         // (2) valid
    2740         ([void, [int, int]])g();      // (3) valid
    2741         ([int, int, int, int])g();    // (4) invalid
    2742         ([int, [int, int, int]])g();  // (5) invalid
     3004        ([int, double])f(); §\C{// (1) valid}§
     3005        ([int, int, int])g(); §\C{// (2) valid}§
     3006        ([void, [int, int]])g(); §\C{// (3) valid}§
     3007        ([int, int, int, int])g(); §\C{// (4) invalid}§
     3008        ([int, [int, int, int]])g(); §\C{// (5) invalid}§
    27433009\end{cfa}
    27443010
     
    28003066void f([int, int], int, int);
    28013067
    2802 f([0, 0], 0, 0);    // no cost
    2803 f(0, 0, 0, 0);      // cost for structuring
    2804 f([0, 0,], [0, 0]); // cost for flattening
    2805 f([0, 0, 0], 0);    // cost for flattening and structuring
     3068f([0, 0], 0, 0); §\C{// no cost}§
     3069f(0, 0, 0, 0); §\C{// cost for structuring}§
     3070f([0, 0,], [0, 0]); §\C{// cost for flattening}§
     3071f([0, 0, 0], 0); §\C{// cost for flattening and structuring}§
    28063072\end{cfa}
    28073073
     
    28663132[ unsigned int, char ]
    28673133[ double, double, double ]
    2868 [ * int, int * ]                §\C{// mix of CFA and ANSI}§
     3134[ * int, int * ] §\C{// mix of CFA and ANSI}§
    28693135[ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    28703136\end{cfa}
     
    28733139Examples of declarations using tuple types are:
    28743140\begin{cfa}
    2875 [ int, int ] x;                 §\C{// 2 element tuple, each element of type int}§
    2876 * [ char, char ] y;             §\C{// pointer to a 2 element tuple}§
     3141[ int, int ] x; §\C{// 2 element tuple, each element of type int}§
     3142* [ char, char ] y; §\C{// pointer to a 2 element tuple}§
    28773143[ [ int, int ] ] z ([ int, int ]);
    28783144\end{cfa}
     
    28913157[ int, int ] w1;
    28923158[ int, int, int ] w2;
    2893 [ void ] f (int, int, int); /* three input parameters of type int */
    2894 [ void ] g ([ int, int, int ]); /* 3 element tuple as input */
     3159[ void ] f (int, int, int); §\C{// three input parameters of type int}§
     3160[ void ] g ([ int, int, int ]); §\C{3 element tuple as input}§
    28953161f( [ 1, 2, 3 ] );
    28963162f( w1, 3 );
     
    29723238[ int, int, int, int ] w = [ 1, 2, 3, 4 ];
    29733239int x = 5;
    2974 [ x, w ] = [ w, x ];            §\C{// all four tuple coercions}§
     3240[ x, w ] = [ w, x ]; §\C{// all four tuple coercions}§
    29753241\end{cfa}
    29763242Starting on the right-hand tuple in the last assignment statement, w is opened, producing a tuple of four values;
     
    30603326both these examples produce indeterminate results:
    30613327\begin{cfa}
    3062 f( x++, x++ );                          §\C{// C routine call with side effects in arguments}§
    3063 [ v1, v2 ] = [ x++, x++ ];      §\C{// side effects in righthand side of multiple assignment}§
     3328f( x++, x++ ); §\C{// C routine call with side effects in arguments}§
     3329[ v1, v2 ] = [ x++, x++ ]; §\C{// side effects in righthand side of multiple assignment}§
    30643330\end{cfa}
    30653331
     
    30833349
    30843350
    3085 \section{I/O Library}
    3086 \label{s:IOLibrary}
    3087 \index{input/output library}
    3088 
    3089 The goal of \CFA I/O is to simplify the common cases\index{I/O!common case}, while fully supporting polymorphism and user defined types in a consistent way.
    3090 The approach combines ideas from \CC and Python.
    3091 The \CFA header file for the I/O library is \Indexc{fstream}.
    3092 
    3093 The common case is printing out a sequence of variables separated by whitespace.
     3351\section{Stream I/O Library}
     3352\label{s:StreamIOLibrary}
     3353\index{input/output stream library}
     3354\index{stream library}
     3355
     3356The goal of \CFA stream input/output (I/O) is to simplify the common cases\index{I/O!common case}, while fully supporting polymorphism and user defined types in a consistent way.
     3357Stream I/O can be implicitly or explicitly formatted.
     3358Implicit formatting means \CFA selects the output or input format for values that match with the type of a variable.
     3359Explicit formatting means additional information is specified to augment how an output or input of value is interpreted.
     3360\CFA formatting is a cross between C ©printf© and \CC ©cout© manipulators, and Python implicit spacing and newline.
     3361Specifically:
     3362\begin{itemize}
     3363\item
     3364©printf©/Python format codes are dense, making them difficult to read and remember.
     3365\CFA/\CC format manipulators are named, making them easier to read and remember.
     3366\item
     3367©printf©/Python separates format codes from associated variables, making it difficult to match codes with variables.
     3368\CFA/\CC co-locate codes with associated variables, where \CFA has the tighter binding.
     3369\item
     3370Format manipulators in \CFA have local effect, whereas \CC have global effect, except ©setw©.
     3371Hence, it is common programming practice to toggle manipulators on and then back to the default to prevent downstream side-effects.
     3372Without this programming style, errors occur when moving prints, as manipulator effects incorrectly flow into the new location.
     3373(To guarantee no side-effects, manipulator values must be saved and restored across function calls.)
     3374\item
     3375\CFA has more sophisticated implicit spacing between values than Python, plus implicit newline at the end of a print.
     3376\end{itemize}
     3377The \CFA header file for the I/O library is \Indexc{fstream.hfa}.
     3378
     3379For implicit formatted output, the common case is printing a series of variables separated by whitespace.
    30943380\begin{cquote}
    3095 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    3096 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
     3381\begin{tabular}{@{}l@{\hspace{2em}}l@{\hspace{2em}}l@{}}
     3382\multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CC}}       & \multicolumn{1}{c}{\textbf{Python}}   \\
    30973383\begin{cfa}
    30983384int x = 1, y = 2, z = 3;
    3099 sout | x ®|® y ®|® z | endl;
     3385sout | x ®|® y ®|® z;
    31003386\end{cfa}
    31013387&
     
    31033389
    31043390cout << x ®<< " "® << y ®<< " "® << z << endl;
     3391\end{cfa}
     3392&
     3393\begin{cfa}
     3394x = 1;  y = 2;  z = 3
     3395print( x, y, z )
    31053396\end{cfa}
    31063397\\
     
    31103401&
    31113402\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3112 1 2 3
     34031® ®2® ®3
     3404\end{cfa}
     3405&
     3406\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     34071® ®2® ®3
    31133408\end{cfa}
    31143409\end{tabular}
    31153410\end{cquote}
    3116 The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators.
    3117 Similar simplification occurs for \Index{tuple} I/O, which prints all tuple values separated by ``\lstinline[showspaces=true]@, @''.
     3411The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators and newline.
     3412Similar simplification occurs for \Index{tuple} I/O, which flattens the tuple and prints each value separated by ``\lstinline[showspaces=true]@, @''.
    31183413\begin{cfa}
    31193414[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    3120 sout | t1 | t2 | endl;                                  §\C{// print tuples}§
     3415sout | t1 | t2; §\C{// print tuples}§
    31213416\end{cfa}
    31223417\begin{cfa}[showspaces=true,aboveskip=0pt]
    312334181®, ®2®, ®3 4®, ®5®, ®6
    31243419\end{cfa}
    3125 Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment.
     3420Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority \emph{overloadable} operator, other than assignment.
    31263421Therefore, fewer output expressions require parenthesis.
    31273422\begin{cquote}
     
    31303425&
    31313426\begin{cfa}
    3132 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     3427sout | x * 3 | y + 1 | z << 2 | x == y | ®(®x | y®)® | ®(®x || y®)® | ®(®x > z ? 1 : 2®)®;
    31333428\end{cfa}
    31343429\\
     
    31363431&
    31373432\begin{cfa}
    3138 cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
     3433cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << ®(®x | y®)® << ®(®x || y®)® << ®(®x > z ? 1 : 2®)® << endl;
    31393434\end{cfa}
    31403435\\
     
    31453440\end{tabular}
    31463441\end{cquote}
    3147 There is a weak similarity between the \CFA logical-or operator and the Shell pipe-operator for moving data, where data flows in the correct direction for input but the opposite direction for output.
     3442Input and output use a uniform operator, ©|©, rather than separate operators, as in ©>>© and ©<<© for \CC.
     3443There is a weak similarity between the \CFA logical-or operator and the \Index{Shell pipe-operator} for moving data, where data flows in the correct direction for input but the opposite direction for output.
     3444
     3445For implicit formatted input, the common case is reading a sequence of values separated by whitespace, where the type of an input constant must match with the type of the input variable.
     3446\begin{cquote}
     3447\begin{lrbox}{\LstBox}
     3448\begin{cfa}[aboveskip=0pt,belowskip=0pt]
     3449int x;   double y   char z;
     3450\end{cfa}
     3451\end{lrbox}
     3452\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{3em}}l@{}}
     3453\multicolumn{1}{@{}l@{}}{\usebox\LstBox} \\
     3454\multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CC}}       & \multicolumn{1}{c}{\textbf{Python}}   \\
     3455\begin{cfa}[aboveskip=0pt,belowskip=0pt]
     3456sin | x | y | z;
     3457\end{cfa}
     3458&
     3459\begin{cfa}[aboveskip=0pt,belowskip=0pt]
     3460cin >> x >> y >> z;
     3461\end{cfa}
     3462&
     3463\begin{cfa}[aboveskip=0pt,belowskip=0pt]
     3464x = int(input());  y = float(input());  z = input();
     3465\end{cfa}
     3466\\
     3467\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3468®1® ®2.5® ®A®
     3469
     3470
     3471\end{cfa}
     3472&
     3473\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3474®1® ®2.5® ®A®
     3475
     3476
     3477\end{cfa}
     3478&
     3479\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3480®1®
     3481®2.5®
     3482®A®
     3483\end{cfa}
     3484\end{tabular}
     3485\end{cquote}
     3486
    31483487
    31493488
    31503489\subsection{Implicit Separator}
    31513490
    3152 The \Index{implicit separator}\index{I/O!separator} character (space/blank) is a separator not a terminator.
     3491The \Index{implicit separator}\index{I/O!separator} character (space/blank) is a separator not a terminator for output.
    31533492The rules for implicitly adding the separator are:
    31543493\begin{enumerate}
     
    31563495A separator does not appear at the start or end of a line.
    31573496\begin{cfa}[belowskip=0pt]
    3158 sout | 1 | 2 | 3 | endl;
     3497sout | 1 | 2 | 3;
    31593498\end{cfa}
    31603499\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    31653504A separator does not appear before or after a character literal or variable.
    31663505\begin{cfa}
    3167 sout | '1' | '2' | '3' | endl;
     3506sout | '1' | '2' | '3';
    31683507123
    31693508\end{cfa}
    31703509
    31713510\item
    3172 A separator does not appear before or after a null (empty) C string.
    3173 \begin{cfa}
    3174 sout | 1 | "" | 2 | "" | 3 | endl;
     3511A separator does not appear before or after a null (empty) C string, which is a local mechanism to disable insertion of the separator character.
     3512\begin{cfa}
     3513sout | 1 | "" | 2 | "" | 3;
    31753514123
    31763515\end{cfa}
    3177 which is a local mechanism to disable insertion of the separator character.
    3178 
    3179 \item
    3180 A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$£¥¡¿«@
     3516
     3517\item
     3518{\lstset{language=CFA,deletedelim=**[is][]{¢}{¢}}
     3519A 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.
     3520\begin{cfa}[belowskip=0pt]
     3521sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
     3522                | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
     3523\end{cfa}
     3524\begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
     35251®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7§\color{red}\textcent§ x 8®»® x 9®)® x 10®]® x 11®}® x
     3526\end{cfa}}%
     3527
     3528\item
     3529A 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.
    31813530%$
    31823531\begin{cfa}[mathescape=off]
    31833532sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
    3184                 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
     3533                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
    31853534\end{cfa}
    31863535%$
     
    31893538\end{cfa}
    31903539%$
    3191 where \lstinline[basicstyle=\tt]@¡¿@ are inverted opening exclamation and question marks, and \lstinline[basicstyle=\tt]@«@ is an opening citation mark.
    3192 
    3193 \item
    3194 {\lstset{language=CFA,deletedelim=**[is][]{¢}{¢}}
    3195 A seperator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[basicstyle=\tt]@,.;!?)]}%¢»@
     3540
     3541\item
     3542A 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@
    31963543\begin{cfa}[belowskip=0pt]
    3197 sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    3198                 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;
    3199 \end{cfa}
    3200 \begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
    3201 1®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7§\color{red}\textcent§ x 8®»® x 9®)® x 10®]® x 11®}® x
    3202 \end{cfa}}%
    3203 where \lstinline[basicstyle=\tt]@»@ is a closing citation mark.
    3204 
    3205 \item
    3206 A seperator does not appear before or after a C string begining/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]@`'": \t\v\f\r\n@
    3207 \begin{cfa}[belowskip=0pt]
    3208 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;
     3544sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx";
    32093545\end{cfa}
    32103546\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     
    32153551If a space is desired before or after one of the special string start/end characters, simply insert a space.
    32163552\begin{cfa}[belowskip=0pt]
    3217 sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4 | endl;
     3553sout | "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;
    32183554\end{cfa}
    32193555\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     
    32233559
    32243560
    3225 \subsection{Manipulator}
    3226 
    3227 The following \CC-style \Index{manipulator}s and routines control implicit seperation.
     3561\subsection{Separation Manipulators}
     3562
     3563The following \Index{manipulator}s control \Index{implicit output separation}.
     3564The effect of these manipulators is global for an output stream (except ©sepOn© and ©sepOff©).
    32283565\begin{enumerate}
    32293566\item
    3230 Routines \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.
     3567\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.
    32313568The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    32323569\begin{cfa}[mathescape=off,belowskip=0pt]
    3233 sepSet( sout, ", $" );                                          §\C{// set separator from " " to ", \$"}§
    3234 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl;
     3570sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§
     3571sout | 1 | 2 | 3 | " \"" | ®sep® | "\"";
    32353572\end{cfa}
    32363573%$
     
    32403577%$
    32413578\begin{cfa}[belowskip=0pt]
    3242 sepSet( sout, " " );                                            §\C{// reset separator to " "}§
    3243 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
     3579sepSet( sout, " " ); §\C{// reset separator to " "}§
     3580sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"";
    32443581\end{cfa}
    32453582\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    32483585©sepGet© can be used to store a separator and then restore it:
    32493586\begin{cfa}[belowskip=0pt]
    3250 char store[®sepSize®];                                          §\C{// sepSize is the maximum separator size}§
    3251 strcpy( store, sepGet( sout ) );                          §\C{// copy current separator}§
    3252 sepSet( sout, "_" );                                            §\C{// change separator to underscore}§
    3253 sout | 1 | 2 | 3 | endl;
     3587char store[®sepSize®]; §\C{// sepSize is the maximum separator size}§
     3588strcpy( store, sepGet( sout ) ); §\C{// copy current separator}§
     3589sepSet( sout, "_" ); §\C{// change separator to underscore}§
     3590sout | 1 | 2 | 3;
    32543591\end{cfa}
    32553592\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    32573594\end{cfa}
    32583595\begin{cfa}[belowskip=0pt]
    3259 sepSet( sout, store );                                          §\C{// change separator back to original}§
    3260 sout | 1 | 2 | 3 | endl;
     3596sepSet( sout, store ); §\C{// change separator back to original}§
     3597sout | 1 | 2 | 3;
    32613598\end{cfa}
    32623599\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    32653602
    32663603\item
    3267 Routine \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepTuple}\index{manipulator!sepTuple@©sepTuple©}/\Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string.
     3604\Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepTuple}\index{manipulator!sepTuple@©sepTuple©}/\Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string.
    32683605The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    32693606\begin{cfa}[belowskip=0pt]
    3270 sepSetTuple( sout, " " );                                       §\C{// set tuple separator from ", " to " "}§
    3271 sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl;
     3607sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§
     3608sout | t1 | t2 | " \"" | ®sepTuple® | "\"";
    32723609\end{cfa}
    32733610\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    32753612\end{cfa}
    32763613\begin{cfa}[belowskip=0pt]
    3277 sepSetTuple( sout, ", " );                                      §\C{// reset tuple separator to ", "}§
    3278 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
     3614sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§
     3615sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"";
    32793616\end{cfa}
    32803617\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    32843621
    32853622\item
    3286 Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items.
     3623\Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} toggle printing the separator.
    32873624\begin{cfa}[belowskip=0pt]
    3288 sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// globally turn off implicit separator}§
     3625sout | sepDisable | 1 | 2 | 3; §\C{// turn off implicit separator}§
    32893626\end{cfa}
    32903627\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    32923629\end{cfa}
    32933630\begin{cfa}[belowskip=0pt]
    3294 sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// globally turn on implicit separator}§
     3631sout | sepEnable | 1 | 2 | 3; §\C{// turn on implicit separator}§
    32953632\end{cfa}
    32963633\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    32993636
    33003637\item
    3301 Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item.
     3638\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.
    33023639\begin{cfa}[belowskip=0pt]
    3303 sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// locally turn off implicit separator
     3640sout | 1 | sepOff | 2 | 3; §\C{// turn off implicit separator for the next item
    33043641\end{cfa}
    33053642\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33073644\end{cfa}
    33083645\begin{cfa}[belowskip=0pt]
    3309 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator
     3646sout | sepDisable | 1 | sepOn | 2 | 3; §\C{// turn on implicit separator for the next item
    33103647\end{cfa}
    33113648\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33143651The tuple separator also responses to being turned on and off.
    33153652\begin{cfa}[belowskip=0pt]
    3316 sout | t1 | sepOff | t2 | endl;                         §\C{// locally turn on/off implicit separator
     3653sout | t1 | sepOff | t2; §\C{// turn off implicit separator for the next item
    33173654\end{cfa}
    33183655\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33223659use ©sep© to accomplish this functionality.
    33233660\begin{cfa}[belowskip=0pt]
    3324 sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       §\C{// sepOn does nothing at start/end of line}§
     3661sout | sepOn | 1 | 2 | 3 | sepOn; §\C{// sepOn does nothing at start/end of line}§
    33253662\end{cfa}
    33263663\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33283665\end{cfa}
    33293666\begin{cfa}[belowskip=0pt]
    3330 sout | sep | 1 | 2 | 3 | sep | endl ;           §\C{// use sep to print separator at start/end of line}§
     3667sout | sep | 1 | 2 | 3 | sep ; §\C{// use sep to print separator at start/end of line}§
    33313668\end{cfa}
    33323669\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    33333670® ®1 2 3® ®
     3671\end{cfa}
     3672\end{enumerate}
     3673
     3674
     3675\subsection{Newline Manipulators}
     3676
     3677The following \Index{manipulators} control \Index{newline separation} for input and output.
     3678
     3679For input:
     3680\begin{enumerate}[parsep=0pt]
     3681\item
     3682\Indexc{nl}\index{manipulator!nl@©nl©} scans characters until the next newline character, i.e., ignore the remaining characters in the line.
     3683\item
     3684\Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} reads the newline character, when reading single characters.
     3685\item
     3686\Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} read the newline character, when reading single characters.
     3687\end{enumerate}
     3688For example, in:
     3689\begin{cfa}
     3690sin | i | ®nl® | j;
     36911 ®2®
     36923
     3693\end{cfa}
     3694variable ©i© is assigned 1, the 2 is skipped, and variable ©j© is assigned 3.
     3695
     3696For output:
     3697\begin{enumerate}[parsep=0pt]
     3698\item
     3699\Indexc{nl}\index{manipulator!nl@©nl©} inserts a newline.
     3700\begin{cfa}
     3701sout | nl; §\C{// only print newline}§
     3702sout | 2; §\C{// implicit newline}§
     3703sout | 3 | nl | 4 | nl; §\C{// terminating nl merged with implicit newline}§
     3704sout | 5 | nl | nl; §\C{// again terminating nl merged with implicit newline}§
     3705sout | 6; §\C{// implicit newline}§
     3706
     37072
     37083
     37094
     37105
     3711
     37126
     3713\end{cfa}
     3714Note, a terminating ©nl© is merged (overrides) with the implicit newline at the end of the ©sout© expression, otherwise it is impossible to to print a single newline
     3715\item
     3716\Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} implicitly prints a newline at the end of each output expression.
     3717\item
     3718\Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} implicitly print a newline at the end of each output expression.
     3719\end{enumerate}
     3720
     3721
     3722\subsection{Output Value Manipulators}
     3723
     3724The following \Index{manipulator}s control formatting of output values (printing), and only affect the format of the argument.
     3725\begin{enumerate}
     3726\item
     3727\Indexc{bin}( integer )\index{manipulator!bin@©bin©} print value in base 2 preceded by ©0b©/©0B©.
     3728\begin{cfa}[belowskip=0pt]
     3729sout | bin( 0 ) | bin( 27HH ) | bin( 27H ) | bin( 27 ) | bin( 27L );
     37300b0 0b11011 0b11011 0b11011 0b11011
     3731sout | bin( -27HH ) | bin( -27H ) | bin( -27 ) | bin( -27L );
     37320b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b®(58 1s)®100101
     3733\end{cfa}
     3734
     3735\item
     3736\Indexc{oct}( integer )\index{manipulator!oct@©oct©} print value in base 8 preceded by ©0©.
     3737\begin{cfa}[belowskip=0pt]
     3738sout | oct( 0 ) | oct( 27HH ) | oct( 27H ) | oct( 27 ) | oct( 27L );
     37390 033 033 033 033
     3740sout | oct( -27HH ) | oct( -27H ) | oct( -27 ) | oct( -27L );
     37410345 0177745 037777777745 01777777777777777777745
     3742\end{cfa}
     3743Note, octal 0 is \emph{not} preceded by ©0© to prevent confusion.
     3744
     3745\item
     3746\Indexc{hex}( integer / floating-point )\index{manipulator!hex@©hex©} print value in base 16 preceded by ©0x©/©0X©.
     3747\begin{cfa}[belowskip=0pt]
     3748sout | hex( 0 ) | hex( 27HH ) | hex( 27H ) | hex( 27 ) | hex( 27L );
     37490 0x1b 0x1b 0x1b 0x1b
     3750sout | hex( -27HH ) | hex( -27H ) | hex( -27 ) | hex( -27L );
     37510xe5 0xffe5 0xffffffe5 0xffffffffffffffe5
     3752
     3753sout | hex( 0.0 ) | hex( 27.5F ) | hex( 27.5 ) | hex( 27.5L );
     37540x0.p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
     3755sout | hex( -27.5F ) | hex( -27.5 ) | hex( -27.5L );
     3756-0x1.b8p+4 -0x1.b8p+4 -0xd.cp+1
     3757\end{cfa}
     3758
     3759\item
     3760\Indexc{sci}( floating-point )\index{manipulator!sci@©sci©} print value in scientific notation with exponent.
     3761Default is 6 digits of precision.
     3762\begin{cfa}[belowskip=0pt]
     3763sout | sci( 0.0 ) | sci( 27.5 ) | sci( -27.5 );
     37640.000000e+00 2.750000e+01 -2.750000e+01
     3765\end{cfa}
     3766
     3767\item
     3768\Indexc{upcase}( bin / hex / floating-point )\index{manipulator!upcase@©upcase©} print letters in a value in upper case. Lower case is the default.
     3769\begin{cfa}[belowskip=0pt]
     3770sout | upcase( bin( 27 ) ) | upcase( hex( 27 ) ) | upcase( 27.5e-10 ) | upcase( hex( 27.5 ) );
     37710®B®11011 0®X®1®B® 2.75®E®-09 0®X®1.®B®8®P®+4
     3772\end{cfa}
     3773
     3774\item
     3775\Indexc{nobase}( integer )\index{manipulator!nobase@©nobase©} do not precede ©bin©, ©oct©, ©hex© with ©0b©/©0B©, ©0©, or ©0x©/©0X©.
     3776Printing the base is the default.
     3777\begin{cfa}[belowskip=0pt]
     3778sout | nobase( bin( 27 ) ) | nobase( oct( 27 ) ) | nobase( hex( 27 ) );
     377911011 33 1b
     3780\end{cfa}
     3781
     3782\item
     3783\Indexc{nodp}( floating-point )\index{manipulator!nodp@©nodp©} do not print a decimal point if there are no fractional digits.
     3784Printing a decimal point is the default, if there are no fractional digits.
     3785\begin{cfa}[belowskip=0pt]
     3786sout | 0. | nodp( 0. ) | 27.0 | nodp( 27.0 ) | nodp( 27.5 );
     37870.0 ®0® 27.0 ®27® 27.5
     3788\end{cfa}
     3789
     3790\item
     3791\Indexc{sign}( integer / floating-point )\index{manipulator!sign@©sign©} prefix with plus or minus sign (©+© or ©-©). Only printing the minus sign is the default.
     3792\begin{cfa}[belowskip=0pt]
     3793sout | sign( 27 ) | sign( -27 ) | sign( 27. ) | sign( -27. ) | sign( 27.5 ) | sign( -27.5 );
     3794®+®27 -27 ®+®27.0 -27.0 ®+®27.5 -27.5
     3795\end{cfa}
     3796
     3797\item
     3798\Indexc{wd}©( unsigned char minimum, T val )©\index{manipulator!wd@©wd©}, ©wd( unsigned char minimum, unsigned char precision, T val )©
     3799For all types, ©minimum© is the minimum number of printed characters.
     3800If the value is shorter than the minimum, it is padded on the right with spaces.
     3801\begin{cfa}[belowskip=0pt]
     3802sout | wd( 4, 34) | wd( 3, 34 ) | wd( 2, 34 );
     3803sout | wd( 10, 4.) | wd( 9, 4. ) | wd( 8, 4. );
     3804sout | wd( 4, "ab" ) | wd( 3, "ab" ) | wd( 2, "ab" );
     3805\end{cfa}
     3806\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3807®  ®34 ® ®34 34
     3808®  ®4.000000 ® ®4.000000 4.000000
     3809®  ®ab ® ®ab ab
     3810\end{cfa}
     3811If the value is larger, it is printed without truncation, ignoring the ©minimum©.
     3812\begin{cfa}[belowskip=0pt]
     3813sout | wd( 4, 34567 ) | wd( 3, 34567 ) | wd( 2, 34567 );
     3814sout | wd( 4, 3456. ) | wd( 3, 3456. ) | wd( 2, 3456. );
     3815sout | wd( 4, "abcde" ) | wd( 3, "abcde" ) | wd( 2,"abcde" );
     3816\end{cfa}
     3817\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     38183456®7® 345®67® 34®567®
     38193456®.® 345®6.® 34®56.®
     3820abcd®e® abc®de® ab®cde®
     3821\end{cfa}
     3822
     3823For integer types, ©precision© is the minimum number of printed digits.
     3824If the value is shorter, it is padded on the left with leading zeros.
     3825\begin{cfa}[belowskip=0pt]
     3826sout | wd( 4,3, 34 ) | wd( 8,4, 34 ) | wd( 10,10, 34 );
     3827\end{cfa}
     3828\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3829 ®0®34     ®00®34 ®00000000®34
     3830\end{cfa}
     3831If the value is larger, it is printed without truncation, ignoring the ©precision©.
     3832\begin{cfa}[belowskip=0pt]
     3833sout | wd( 4,1, 3456 ) | wd( 8,2, 3456 ) | wd( 10,3, 3456 );
     3834\end{cfa}
     3835\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     38363456     3456       3456
     3837\end{cfa}
     3838If ©precision© is 0, nothing is printed for zero.
     3839If ©precision© is greater than the minimum, it becomes the minimum.
     3840\begin{cfa}[belowskip=0pt]
     3841sout | wd( 4,0, 0 ) | wd( 3,10, 34 );
     3842\end{cfa}
     3843\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3844®    ® ®00000000®34
     3845\end{cfa}
     3846For floating-point types, ©precision© is the minimum number of digits after the decimal point.
     3847\begin{cfa}[belowskip=0pt]
     3848sout | wd( 6,3, 27.5 ) | wd( 8,1, 27.5 ) | wd( 8,0, 27.5 ) | wd( 3,8, 27.5 );
     3849\end{cfa}
     3850\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     385127.®500®     27.®5®      28. 27.®50000000®
     3852\end{cfa}
     3853For the C-string type, ©precision© is the maximum number of printed characters, so the string is truncared if it exceeds the maximum.
     3854\begin{cfa}[belowskip=0pt]
     3855sout | wd( 6,8, "abcd" ) | wd( 6,8, "abcdefghijk" ) | wd( 6,3, "abcd" );
     3856\end{cfa}
     3857\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3858  abcd abcdefgh    abc
     3859\end{cfa}
     3860
     3861\item
     3862\Indexc{ws( unsigned char minimum, unsigned char significant, floating-point )}\index{manipulator!ws@©ws©}
     3863For floating-point type, ©minimum© is the same as for manipulator ©wd©, but ©significant© is the maximum number of significant digits to be printed for both the integer and fractions (versus only the fraction for ©wd©).
     3864If a value's significant digits is greater than ©significant©, the last significant digit is rounded up.
     3865\begin{cfa}[belowskip=0pt]
     3866sout | ws(6,6, 234.567) | ws(6,5, 234.567) | ws(6,4, 234.567) | ws(6,3, 234.567);
     3867\end{cfa}
     3868\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3869234.567 234.5®7®  234.®6®    23®5®
     3870\end{cfa}
     3871If a value's magnitude is greater than ©significant©, the value is printed in scientific notation with the specified number of significant digits.
     3872\begin{cfa}[belowskip=0pt]
     3873sout | ws(6,6, 234567.) | ws(6,5, 234567.) | ws(6,4, 234567.) | ws(6,3, 234567.);
     3874\end{cfa}
     3875\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3876234567. 2.3457®e+05® 2.346®e+05® 2.35®e+05®
     3877\end{cfa}
     3878If ©significant© is greater than ©minimum©, it defines the number of printed characters.
     3879\begin{cfa}[belowskip=0pt]
     3880sout | ws(3,6, 234567.) | ws(4,6, 234567.) | ws(5,6, 234567.) | ws(6,6, 234567.);
     3881\end{cfa}
     3882\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3883234567. 234567. 234567. 234567.
     3884\end{cfa}
     3885
     3886\item
     3887\Indexc{left}( field-width )\index{manipulator!left@©left©} left justify within the given field.
     3888\begin{cfa}[belowskip=0pt]
     3889sout | left(wd(4, 27)) | left(wd(10, 27.)) | left(wd(10, 27.5)) | left(wd(4,3, 27)) | left(wd(10,3, 27.5));
     3890\end{cfa}
     3891\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     389227®  ® 27.000000  27.500000  027  27.500®    ®
     3893\end{cfa}
     3894
     3895\item
     3896\Indexc{pad0}( field-width )\index{manipulator!pad0@©pad0©} left pad with zeroes (0).
     3897\begin{cfa}[belowskip=0pt]
     3898sout | pad0( wd( 4, 27 ) ) | pad0( wd( 4,3, 27 ) ) | pad0( wd( 8,3, 27.5 ) );
     3899®00®27  ®0®27 ®00®27.500
    33343900\end{cfa}
    33353901\end{enumerate}
     
    33413907int main( void ) {
    33423908        int x = 1, y = 2, z = 3;
    3343         sout | x | y | z | endl;
     3909        sout | x | y | z;
    33443910        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    3345         sout | t1 | t2 | endl;                                          // print tuples
    3346         sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
    3347         sout | 1 | 2 | 3 | endl;
    3348         sout | '1' | '2' | '3' | endl;
    3349         sout | 1 | "" | 2 | "" | 3 | endl;
     3911        sout | t1 | t2;                                         // print tuples
     3912        sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2);
     3913        sout | 1 | 2 | 3;
     3914        sout | '1' | '2' | '3';
     3915        sout | 1 | "" | 2 | "" | 3;
    33503916        sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
    3351                 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
     3917                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
    33523918        sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    3353                 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;
    3354         sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;
    3355         sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;
     3919                | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
     3920        sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx";
     3921        sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4;
    33563922
    33573923        sepSet( sout, ", $" );                                          // set separator from " " to ", $"
    3358         sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl;
     3924        sout | 1 | 2 | 3 | " \"" | sep | "\"";
    33593925        sepSet( sout, " " );                                            // reset separator to " "
    3360         sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
     3926        sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"";
    33613927
    33623928        char store[sepSize];
    33633929        strcpy( store, sepGet( sout ) );
    33643930        sepSet( sout, "_" );
    3365         sout | 1 | 2 | 3 | endl;
     3931        sout | 1 | 2 | 3;
    33663932        sepSet( sout, store );
    3367         sout | 1 | 2 | 3 | endl;
     3933        sout | 1 | 2 | 3;
    33683934
    33693935        sepSetTuple( sout, " " );                                       // set tuple separator from ", " to " "
    3370         sout | t1 | t2 | " \"" | sepTuple | "\"" | endl;
     3936        sout | t1 | t2 | " \"" | sepTuple | "\"";
    33713937        sepSetTuple( sout, ", " );                                      // reset tuple separator to ", "
    3372         sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
    3373 
    3374         sout | sepDisable | 1 | 2 | 3 | endl;           // globally turn off implicit separator
    3375         sout | sepEnable | 1 | 2 | 3 | endl;            // globally turn on implicit separator
    3376        
    3377         sout | 1 | sepOff | 2 | 3 | endl;                       // locally turn on implicit separator
    3378         sout | sepDisable | 1 | sepOn | 2 | 3 | endl; // globally turn off implicit separator
     3938        sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"";
     3939
     3940        sout | sepDisable | 1 | 2 | 3;          // globally turn off implicit separator
     3941        sout | sepEnable | 1 | 2 | 3;           // globally turn on implicit separator
     3942
     3943        sout | 1 | sepOff | 2 | 3;                      // locally turn on implicit separator
     3944        sout | sepDisable | 1 | sepOn | 2 | 3; // globally turn off implicit separator
    33793945        sout | sepEnable;
    3380         sout | t1 | sepOff | t2 | endl;                         // locally turn on/off implicit separator
    3381 
    3382         sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       // sepOn does nothing at start/end of line
    3383         sout | sep | 1 | 2 | 3 | sep | endl ;           // use sep to print separator at start/end of line
     3946        sout | t1 | sepOff | t2;                                // locally turn on/off implicit separator
     3947
     3948        sout | sepOn | 1 | 2 | 3 | sepOn ;      // sepOn does nothing at start/end of line
     3949        sout | sep | 1 | 2 | 3 | sep ;          // use sep to print separator at start/end of line
    33843950}
    33853951
     
    33903956\end{comment}
    33913957%$
     3958
     3959
     3960\subsection{Input Value Manipulators}
     3961
     3962The format of numeric input values in the same as C constants without a trailing type suffix, as the input value-type is denoted by the input variable.
     3963For ©_Bool© type, the constants are ©true© and ©false©.
     3964For integral types, any number of digits, optionally preceded by a sign (©+© or ©-©), where a
     3965\begin{itemize}
     3966\item
     3967©1©-©9© prefix introduces a decimal value (©0©-©9©),
     3968\item
     3969©0© prefix introduces an octal value (©0©-©7©), and
     3970\item
     3971©0x© or ©0X© prefix introduces a hexadecimal value (©0©-©f©) with lower or upper case letters.
     3972\end{itemize}
     3973For floating-point types, any number of decimal digits, optionally preceded by a sign (©+© or ©-©), optionally containing a decimal point, and optionally followed by an exponent, ©e© or ©E©, with signed (optional) decimal digits.
     3974Floating-point values can also be written in hexadecimal format preceded by ©0x© or ©0X© with hexadecimal digits and exponent denoted by ©p© or ©P©.
     3975
     3976For the C-string type, the input values are \emph{not} the same as C-string constants, \ie double quotes bracketing arbitrary text with escape sequences.
     3977Instead, the next sequence of non-whitespace characters are read, and the input sequence is terminated with delimiter ©'\0'©.
     3978The string variable \emph{must} be large enough to contain the input sequence.
     3979
     3980The following \Index{manipulator}s control formatting of input values (reading), and only affect the format of the argument.
     3981
     3982\begin{enumerate}
     3983\item
     3984\Indexc{skip( const char * pattern )}\index{manipulator!skip@©skip©} / ©skip( unsigned int length )© / ©const char * pattern©
     3985The argument defines a ©pattern© or ©length©.
     3986The ©pattern© is composed of white-space and non-white-space characters, where \emph{any} white-space character matches 0 or more input white-space characters (hence, consecutive white-space characters in the pattern are combined), and each non-white-space character matches exactly with an input character.
     3987The ©length© is composed of the next $N$ characters, including the newline character.
     3988If the match successes, the input characters are discarded, and input continues with the next character.
     3989If the match fails, the input characters are left unread.
     3990\begin{cfa}[belowskip=0pt]
     3991char sk[$\,$] = "abc";
     3992sin | "abc " | skip( sk ) | skip( 5 ); // match input sequence
     3993\end{cfa}
     3994\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     3995®abc   ®
     3996®abc  ®
     3997®xx®
     3998\end{cfa}
     3999
     4000\item
     4001\Indexc{wdi}©( unsigned int maximum, T & val )©\index{manipulator!wdi@©wdi©}
     4002For all types except ©char©, ©maximum© is the maximum number of characters read for the current operation.
     4003\begin{cfa}[belowskip=0pt]
     4004char s[10];   int i;   double d;   
     4005sin | wdi( 4, s ) | wdi( 3, i ) | wdi( 8, d );  // c == "abcd", i == 123, d == 3.456E+2
     4006\end{cfa}
     4007\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     4008®abcd1233.456E+2®
     4009\end{cfa}
     4010Note, input ©wdi© cannot be overloaded with output ©wd© because both have the same parameters but return different types.
     4011Currently, \CFA cannot distinguish between these two manipulators in the middle of an ©sout©/©sin© expression based on return type.
     4012
     4013\item
     4014\Indexc{ignore( T & val )}\index{manipulator!ignore@©ignore©}
     4015For all types, the data is read from the stream depending on the argument type but ignored, \ie it is not stored in the argument.
     4016\begin{cfa}[belowskip=0pt]
     4017double d;
     4018sin | ignore( d );  // d is unchanged
     4019\end{cfa}
     4020\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     4021®  -75.35e-4® 25
     4022\end{cfa}
     4023
     4024\item
     4025\Indexc{incl( const char * scanset, char * s )}\index{manipulator!incl@©incl©}
     4026For the C-string type, the argument defines a ©scanset© that matches any number of characters \emph{in} the set.
     4027Matching characters are read into the C string and null terminated.
     4028\begin{cfa}[belowskip=0pt]
     4029char s[10];
     4030sin | incl( "abc", s );
     4031\end{cfa}
     4032\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     4033®bca®xyz
     4034\end{cfa}
     4035
     4036\item
     4037\Indexc{excl( const char * scanset, char * s )}\index{manipulator!excl@©excl©}
     4038For the C-string type, the argument defines a ©scanset© that matches any number of characters \emph{not in} the set.
     4039Non-matching characters are read into the C string and null terminated.
     4040\begin{cfa}[belowskip=0pt]
     4041char s[10];
     4042sin | excl( "abc", s );
     4043\end{cfa}
     4044\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     4045®xyz®bca
     4046\end{cfa}
     4047\end{enumerate}
    33924048
    33934049
     
    37594415\begin{itemize}
    37604416\item
    3761 preventing having to determine or write long generic types,
    3762 \item
    3763 ensure secondary variables, related to a primary variable, always have the same type.
     4417not determining or writing long generic types,
     4418\item
     4419ensuring secondary variables, related to a primary variable, always have the same type.
    37644420\end{itemize}
    37654421
     
    37834439There is also the conundrum in type inferencing of when to \emph{\Index{brand}} a type.
    37844440That is, when is the type of the variable more important than the type of its initialization expression.
    3785 For example, if a change is made in an initialization expression, it can cause significant cascading type changes and/or errors.
     4441For example, if a change is made in an initialization expression, it can cause cascading type changes and/or errors.
    37864442At some point, a variable type needs to remain constant and the expression to be in error when it changes.
    37874443
     
    40164672
    40174673coroutine Fibonacci {
    4018         int fn;                                                         §\C{// used for communication}§
     4674        int fn; §\C{// used for communication}§
    40194675};
    40204676void ?{}( Fibonacci * this ) {
     
    40224678}
    40234679void main( Fibonacci * this ) {
    4024         int fn1, fn2;                                           §\C{// retained between resumes}§
    4025         this->fn = 0;                                           §\C{// case 0}§
     4680        int fn1, fn2; §\C{// retained between resumes}§
     4681        this->fn = 0; §\C{// case 0}§
    40264682        fn1 = this->fn;
    4027         suspend();                                                      §\C{// return to last resume}§
    4028 
    4029         this->fn = 1;                                           §\C{// case 1}§
     4683        suspend(); §\C{// return to last resume}§
     4684
     4685        this->fn = 1; §\C{// case 1}§
    40304686        fn2 = fn1;
    40314687        fn1 = this->fn;
    4032         suspend();                                                      §\C{// return to last resume}§
    4033 
    4034         for ( ;; ) {                                            §\C{// general case}§
     4688        suspend(); §\C{// return to last resume}§
     4689
     4690        for ( ;; ) { §\C{// general case}§
    40354691                this->fn = fn1 + fn2;
    40364692                fn2 = fn1;
    40374693                fn1 = this->fn;
    4038                 suspend();                                              §\C{// return to last resume}§
     4694                suspend(); §\C{// return to last resume}§
    40394695        } // for
    40404696}
    40414697int next( Fibonacci * this ) {
    4042         resume( this );                                         §\C{// transfer to last suspend}§
     4698        resume( this ); §\C{// transfer to last suspend}§
    40434699        return this->fn;
    40444700}
     
    40464702        Fibonacci f1, f2;
    40474703        for ( int i = 1; i <= 10; i += 1 ) {
    4048                 sout | next( &f1 ) | ' ' | next( &f2 ) | endl;
     4704                sout | next( &f1 ) | ' ' | next( &f2 );
    40494705        } // for
    40504706}
     
    41124768                MyThread f[4];
    41134769        }
    4114         sout | global.value | endl;
     4770        sout | global.value;
    41154771}
    41164772\end{cfa}
     
    41904846void main( First * this ) {
    41914847        for ( int i = 0; i < 10; i += 1 ) {
    4192                 sout | "First : Suspend No." | i + 1 | endl;
     4848                sout | "First : Suspend No." | i + 1;
    41934849                yield();
    41944850        }
     
    41994855        wait( this->lock );
    42004856        for ( int i = 0; i < 10; i += 1 ) {
    4201                 sout | "Second : Suspend No." | i + 1 | endl;
     4857                sout | "Second : Suspend No." | i + 1;
    42024858                yield();
    42034859        }
     
    42064862int main( void ) {
    42074863        signal_once lock;
    4208         sout | "User main begin" | endl;
     4864        sout | "User main begin";
    42094865        {
    42104866                processor p;
     
    42144870                }
    42154871        }
    4216         sout | "User main end" | endl;
     4872        sout | "User main end";
    42174873}
    42184874\end{cfa}
     
    49115567void ?{}( Line * l ) {
    49125568        l->lnth = 0.0;
    4913         sout | "default" | endl;
     5569        sout | "default";
    49145570}
    49155571
     
    49185574void ?{}( Line * l, float lnth ) {
    49195575        l->lnth = lnth;
    4920         sout | "lnth" | l->lnth | endl;
     5576        sout | "lnth" | l->lnth;
    49215577
    49225578}
     
    49245580// destructor
    49255581void ^?() {
    4926         sout | "destroyed" | endl;
     5582        sout | "destroyed";
    49275583        l.lnth = 0.0;
    49285584}
     
    55856241In \CFA, there are ambiguous cases with dereference and operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be interpreted as:
    55866242\begin{cfa}
    5587 *?§\color{red}\textvisiblespace§*?              §\C{// dereference operator, dereference operator}§
    5588 *§\color{red}\textvisiblespace§?*?              §\C{// dereference, multiplication operator}§
     6243*?§\color{red}\textvisiblespace§*? §\C{// dereference operator, dereference operator}§
     6244*§\color{red}\textvisiblespace§?*? §\C{// dereference, multiplication operator}§
    55896245\end{cfa}
    55906246By default, the first interpretation is selected, which does not yield a meaningful parse.
     
    56386294\eg:
    56396295\begin{cfa}
    5640 x;                                                              §\C{// int x}§
    5641 *y;                                                             §\C{// int *y}§
    5642 f( p1, p2 );                                    §\C{// int f( int p1, int p2 );}§
    5643 g( p1, p2 ) int p1, p2;                 §\C{// int g( int p1, int p2 );}§
     6296x; §\C{// int x}§
     6297*y; §\C{// int *y}§
     6298f( p1, p2 ); §\C{// int f( int p1, int p2 );}§
     6299g( p1, p2 ) int p1, p2; §\C{// int g( int p1, int p2 );}§
    56446300\end{cfa}
    56456301\CFA continues to support K\&R routine definitions:
    56466302\begin{cfa}
    5647 f( a, b, c )                                    §\C{// default int return}§
    5648         int a, b; char c                        §\C{// K\&R parameter declarations}§
     6303f( a, b, c ) §\C{// default int return}§
     6304        int a, b; char c §\C{// K\&R parameter declarations}§
    56496305{
    56506306        ...
     
    56656321int rtn( int i );
    56666322int rtn( char c );
    5667 rtn( 'x' );                                             §\C{// programmer expects 2nd rtn to be called}§
     6323rtn( 'x' ); §\C{// programmer expects 2nd rtn to be called}§
    56686324\end{cfa}
    56696325\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
    56706326In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
    56716327\begin{cfa}
    5672 sout | 'x' | " " | (int)'x' | endl;
     6328sout | 'x' | " " | (int)'x';
    56736329x 120
    56746330\end{cfa}
     
    56876343\item[Change:] make string literals ©const©:
    56886344\begin{cfa}
    5689 char * p = "abc";                               §\C{// valid in C, deprecated in \CFA}§
    5690 char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
     6345char * p = "abc"; §\C{// valid in C, deprecated in \CFA}§
     6346char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
    56916347\end{cfa}
    56926348The type of a string literal is changed from ©[] char© to ©const [] char©.
     
    56956351\begin{cfa}
    56966352char * p = "abc";
    5697 p[0] = 'w';                                             §\C{// segment fault or change constant literal}§
     6353p[0] = 'w'; §\C{// segment fault or change constant literal}§
    56986354\end{cfa}
    56996355The same problem occurs when passing a string literal to a routine that changes its argument.
     
    57076363\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
    57086364\begin{cfa}
    5709 int i;                                                  §\C{// forward definition}§
    5710 int *j = ®&i®;                                  §\C{// forward reference, valid in C, invalid in \CFA}§
    5711 int i = 0;                                              §\C{// definition}§
     6365int i; §\C{// forward definition}§
     6366int *j = ®&i®; §\C{// forward reference, valid in C, invalid in \CFA}§
     6367int i = 0; §\C{// definition}§
    57126368\end{cfa}
    57136369is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
     
    57156371\begin{cfa}
    57166372struct X { int i; struct X *next; };
    5717 static struct X a;                              §\C{// forward definition}§
     6373static struct X a; §\C{// forward definition}§
    57186374static struct X b = { 0, ®&a® };§\C{// forward reference, valid in C, invalid in \CFA}§
    5719 static struct X a = { 1, &b };  §\C{// definition}§
     6375static struct X a = { 1, &b }; §\C{// definition}§
    57206376\end{cfa}
    57216377\item[Rationale:] avoids having different initialization rules for builtin types and user-defined types.
     
    57326388struct Person {
    57336389        enum ®Colour® { R, G, B };      §\C[7cm]{// nested type}§
    5734         struct Face {                           §\C{// nested type}§
    5735                 ®Colour® Eyes, Hair;    §\C{// type defined outside (1 level)}§
     6390        struct Face { §\C{// nested type}§
     6391                ®Colour® Eyes, Hair; §\C{// type defined outside (1 level)}§
    57366392        };
    5737         ®.Colour® shirt;                        §\C{// type defined outside (top level)}§
    5738         ®Colour® pants;                         §\C{// type defined same level}§
    5739         Face looks[10];                         §\C{// type defined same level}§
     6393        ®.Colour® shirt; §\C{// type defined outside (top level)}§
     6394        ®Colour® pants; §\C{// type defined same level}§
     6395        Face looks[10]; §\C{// type defined same level}§
    57406396};
    5741 ®Colour® c = R;                                 §\C{// type/enum defined same level}§
     6397®Colour® c = R; §\C{// type/enum defined same level}§
    57426398Person®.Colour® pc = Person®.®R;§\C{// type/enum defined inside}§
    5743 Person®.®Face pretty;                   §\C{// type defined inside}\CRT§
     6399Person®.®Face pretty; §\C{// type defined inside}\CRT§
    57446400\end{cfa}
    57456401In 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.
     
    57586414\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:
    57596415\begin{cfa}
    5760 struct Y;                                               §\C{// struct Y and struct X are at the same scope}§
     6416struct Y; §\C{// struct Y and struct X are at the same scope}§
    57616417struct X {
    57626418        struct Y { /* ... */ } y;
     
    57736429\begin{cfa}
    57746430void foo() {
    5775         int * b = malloc( sizeof(int) );        §\C{// implicitly convert void * to int *}§
    5776         char * c = b;                           §\C{// implicitly convert int * to void *, and then void * to char *}§
     6431        int * b = malloc( sizeof(int) ); §\C{// implicitly convert void * to int *}§
     6432        char * c = b; §\C{// implicitly convert int * to void *, and then void * to char *}§
    57776433}
    57786434\end{cfa}
     
    59476603void * memalign( size_t align, size_t size );§\indexc{memalign}§
    59486604int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
    5949 }
    5950 
    5951 // §\CFA§ safe equivalents, i.e., implicit size specification
    5952 forall( dtype T | sized(T) ) T * malloc( void );
    5953 forall( dtype T | sized(T) ) T * calloc( size_t dim );
    5954 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );
    5955 forall( dtype T | sized(T) ) T * memalign( size_t align );
    5956 forall( dtype T | sized(T) ) T * aligned_alloc( size_t align );
    5957 forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align );
    5958 
    5959 // §\CFA§ safe general allocation, fill, resize, array
    5960 forall( dtype T | sized(T) ) T * alloc( void );§\indexc{alloc}§
    5961 forall( dtype T | sized(T) ) T * alloc( char fill );
    5962 forall( dtype T | sized(T) ) T * alloc( size_t dim );
    5963 forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill );
    5964 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim );
    5965 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
    5966 
    5967 // §\CFA§ safe general allocation, align, fill, array
    5968 forall( dtype T | sized(T) ) T * align_alloc( size_t align );
    5969 forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill );
    5970 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim );
    5971 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill );
    59726605
    59736606// C unsafe initialization/copy
    5974 extern "C" {
    59756607void * memset( void * dest, int c, size_t size );
    59766608void * memcpy( void * dest, const void * src, size_t size );
    59776609}
    59786610
     6611forall( dtype T | sized(T) ) {
     6612// §\CFA§ safe equivalents, i.e., implicit size specification
     6613        T * malloc( void );
     6614        T * calloc( size_t dim );
     6615        T * realloc( T * ptr, size_t size );
     6616        T * memalign( size_t align );
     6617        T * aligned_alloc( size_t align );
     6618        int posix_memalign( T ** ptr, size_t align );
     6619
     6620// §\CFA§ safe general allocation, fill, resize, array
     6621        T * alloc( void );§\indexc{alloc}§
     6622        T * alloc( char fill );
     6623        T * alloc( size_t dim );
     6624        T * alloc( size_t dim, char fill );
     6625        T * alloc( T ptr[], size_t dim );
     6626        T * alloc( T ptr[], size_t dim, char fill );
     6627
     6628// §\CFA§ safe general allocation, align, fill, array
     6629        T * align_alloc( size_t align );
     6630        T * align_alloc( size_t align, char fill );
     6631        T * align_alloc( size_t align, size_t dim );
     6632        T * align_alloc( size_t align, size_t dim, char fill );
     6633
    59796634// §\CFA§ safe initialization/copy, i.e., implicit size specification
    5980 forall( dtype T | sized(T) ) T * memset( T * dest, char c );§\indexc{memset}§
    5981 forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
     6635        T * memset( T * dest, char c );§\indexc{memset}§
     6636        T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
    59826637
    59836638// §\CFA§ safe initialization/copy array
    5984 forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c );
    5985 forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim );
     6639        T * amemset( T dest[], char c, size_t dim );
     6640        T * amemcpy( T dest[], const T src[], size_t dim );
     6641}
    59866642
    59876643// §\CFA§ allocation/deallocation and constructor/destructor
     
    59996655
    60006656
    6001 \subsection{Conversion}
     6657\subsection{String to Value Conversion}
    60026658
    60036659\leavevmode
     
    60356691\leavevmode
    60366692\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6037 forall( otype T | { int ?<?( T, T ); } )        §\C{// location}§
     6693forall( otype T | { int ?<?( T, T ); } ) §\C{// location}§
    60386694T * bsearch( T key, const T * arr, size_t dim );§\indexc{bsearch}§
    60396695
    6040 forall( otype T | { int ?<?( T, T ); } )        §\C{// position}§
     6696forall( otype T | { int ?<?( T, T ); } ) §\C{// position}§
    60416697unsigned int bsearch( T key, const T * arr, size_t dim );
    60426698
    60436699forall( otype T | { int ?<?( T, T ); } )
    60446700void qsort( const T * arr, size_t dim );§\indexc{qsort}§
     6701
     6702forall( otype E | { int ?<?( E, E ); } ) {
     6703        E * bsearch( E key, const E * vals, size_t dim );§\indexc{bsearch}§ §\C{// location}§
     6704        size_t bsearch( E key, const E * vals, size_t dim );§\C{// position}§
     6705        E * bsearchl( E key, const E * vals, size_t dim );§\indexc{bsearchl}§
     6706        size_t bsearchl( E key, const E * vals, size_t dim );
     6707        E * bsearchu( E key, const E * vals, size_t dim );§\indexc{bsearchu}§
     6708        size_t bsearchu( E key, const E * vals, size_t dim );
     6709}
     6710
     6711forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) {
     6712        E * bsearch( K key, const E * vals, size_t dim );
     6713        size_t bsearch( K key, const E * vals, size_t dim );
     6714        E * bsearchl( K key, const E * vals, size_t dim );
     6715        size_t bsearchl( K key, const E * vals, size_t dim );
     6716        E * bsearchu( K key, const E * vals, size_t dim );
     6717        size_t bsearchu( K key, const E * vals, size_t dim );
     6718}
     6719
     6720forall( otype E | { int ?<?( E, E ); } ) {
     6721        void qsort( E * vals, size_t dim );§\indexc{qsort}§
     6722}
    60456723\end{cfa}
    60466724
     
    60696747\leavevmode
    60706748\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6071 void rand48seed( long int s );§\indexc{rand48seed}§
    6072 char rand48();§\indexc{rand48}§
    6073 int rand48();
    6074 unsigned int rand48();
    6075 long int rand48();
    6076 unsigned long int rand48();
    6077 float rand48();
    6078 double rand48();
    6079 float _Complex rand48();
    6080 double _Complex rand48();
    6081 long double _Complex rand48();
     6749void srandom( unsigned int seed );§\indexc{srandom}§
     6750char random( void );§\indexc{random}§
     6751char random( char u ); §\C{// [0,u)}§
     6752char random( char l, char u ); §\C{// [l,u)}§
     6753int random( void );
     6754int random( int u ); §\C{// [0,u)}§
     6755int random( int l, int u ); §\C{// [l,u)}§
     6756unsigned int random( void );
     6757unsigned int random( unsigned int u ); §\C{// [0,u)}§
     6758unsigned int random( unsigned int l, unsigned int u ); §\C{// [l,u)}§
     6759long int random( void );
     6760long int random( long int u ); §\C{// [0,u)}§
     6761long int random( long int l, long int u ); §\C{// [l,u)}§
     6762unsigned long int random( void );
     6763unsigned long int random( unsigned long int u ); §\C{// [0,u)}§
     6764unsigned long int random( unsigned long int l, unsigned long int u ); §\C{// [l,u)}§
     6765float random( void );                                            §\C{// [0.0, 1.0)}§
     6766double random( void );                                           §\C{// [0.0, 1.0)}§
     6767float _Complex random( void );                           §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
     6768double _Complex random( void );                          §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
     6769long double _Complex random( void );             §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
    60826770\end{cfa}
    60836771
     
    61226810[ int, long double ] remquo( long double, long double );
    61236811
    6124 float div( float, float, int * );§\indexc{div}§ §\C{// alternative name for remquo}§
     6812float div( float, float, int * );§\indexc{div}§ §\C{// alternative name for remquo}§
    61256813double div( double, double, int * );
    61266814long double div( long double, long double, int * );
     
    62786966long double atan2( long double, long double );
    62796967
    6280 float atan( float, float );                                     §\C{// alternative name for atan2}§
     6968float atan( float, float ); §\C{// alternative name for atan2}§
    62816969double atan( double, double );§\indexc{atan}§
    62826970long double atan( long double, long double );
     
    64587146
    64597147
    6460 \section{Time}
    6461 \label{s:TimeLib}
     7148\section{Time Keeping}
     7149\label{s:TimeKeeping}
    64627150
    64637151
    64647152%\subsection{\texorpdfstring{\protect\lstinline@Duration@}{Duration}}
    6465 \subsection{\texorpdfstring{\LstKeywordStyle{\textmd{Duration}}}{Duration}}
     7153\subsection{\texorpdfstring{\LstBasicStyle{Duration}}{Duration}}
    64667154\label{s:Duration}
    64677155
     
    64697157\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    64707158struct Duration {
    6471         int64_t tv;                                                     §\C{// nanoseconds}§
     7159        int64_t tv; §\C{// nanoseconds}§
    64727160};
    64737161
     
    65127200
    65137201Duration abs( Duration rhs );
    6514 
    6515 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur );
    65167202
    65177203Duration ?`ns( int64_t nsec );
     
    65377223int64_t ?`d( Duration dur );
    65387224int64_t ?`w( Duration dur );
     7225
     7226Duration max( Duration lhs, Duration rhs );
     7227Duration min( Duration lhs, Duration rhs );
    65397228\end{cfa}
    65407229
    65417230
    65427231%\subsection{\texorpdfstring{\protect\lstinline@\timeval@}{timeval}}
    6543 \subsection{\texorpdfstring{\LstKeywordStyle{\textmd{timeval}}}{timeval}}
     7232\subsection{\texorpdfstring{\LstBasicStyle{timeval}}{timeval}}
    65447233\label{s:timeval}
    65457234
     
    65607249
    65617250
    6562 \subsection{\texorpdfstring{\protect\lstinline@timespec@}{timespec}}
     7251%\subsection{\texorpdfstring{\protect\lstinline@timespec@}{timespec}}
     7252\subsection{\texorpdfstring{\LstBasicStyle{timespec}}{timespec}}
    65637253\label{s:timespec}
    65647254
     
    65797269
    65807270
    6581 \subsection{\texorpdfstring{\protect\lstinline@itimerval@}{itimerval}}
     7271%\subsection{\texorpdfstring{\protect\lstinline@itimerval@}{itimerval}}
     7272\subsection{\texorpdfstring{\LstBasicStyle{itimerval}}{itimerval}}
    65827273\label{s:itimerval}
    65837274
     
    65897280
    65907281
    6591 \subsection{\texorpdfstring{\protect\lstinline@Time@}{Time}}
     7282%\subsection{\texorpdfstring{\protect\lstinline@Time@}{Time}}
     7283\subsection{\texorpdfstring{\LstBasicStyle{Time}}{Time}}
    65927284\label{s:Time}
    65937285
     
    65957287\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    65967288struct Time {
    6597         uint64_t tv;                                            §\C{// nanoseconds since UNIX epoch}§
     7289        uint64_t tv; §\C{// nanoseconds since UNIX epoch}§
    65987290};
    65997291
    66007292void ?{}( Time & time );
    66017293void ?{}( Time & time, zero_t );
    6602 void ?{}( Time & time, int year, int month = 0, int day = 0, int hour = 0, int min = 0, int sec = 0, int nsec = 0 );
     7294
    66037295Time ?=?( Time & time, zero_t );
    66047296
     
    66097301Time ?=?( Time & time, timespec t );
    66107302
    6611 Time ?+?( Time & lhs, Duration rhs ) { return (Time)@{ lhs.tv + rhs.tv }; }
    6612 Time ?+?( Duration lhs, Time rhs ) { return rhs + lhs; }
    6613 Time ?+=?( Time & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; }
    6614 
    6615 Duration ?-?( Time lhs, Time rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; }
    6616 Time ?-?( Time lhs, Duration rhs ) { return (Time)@{ lhs.tv - rhs.tv }; }
    6617 Time ?-=?( Time & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; }
    6618 _Bool ?==?( Time lhs, Time rhs ) { return lhs.tv == rhs.tv; }
    6619 _Bool ?!=?( Time lhs, Time rhs ) { return lhs.tv != rhs.tv; }
    6620 _Bool ?<?( Time lhs, Time rhs ) { return lhs.tv < rhs.tv; }
    6621 _Bool ?<=?( Time lhs, Time rhs ) { return lhs.tv <= rhs.tv; }
    6622 _Bool ?>?( Time lhs, Time rhs ) { return lhs.tv > rhs.tv; }
    6623 _Bool ?>=?( Time lhs, Time rhs ) { return lhs.tv >= rhs.tv; }
    6624 
    6625 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
     7303Time ?+?( Time & lhs, Duration rhs );
     7304Time ?+?( Duration lhs, Time rhs );
     7305Time ?+=?( Time & lhs, Duration rhs );
     7306
     7307Duration ?-?( Time lhs, Time rhs );
     7308Time ?-?( Time lhs, Duration rhs );
     7309Time ?-=?( Time & lhs, Duration rhs );
     7310_Bool ?==?( Time lhs, Time rhs );
     7311_Bool ?!=?( Time lhs, Time rhs );
     7312_Bool ?<?( Time lhs, Time rhs );
     7313_Bool ?<=?( Time lhs, Time rhs );
     7314_Bool ?>?( Time lhs, Time rhs );
     7315_Bool ?>=?( Time lhs, Time rhs );
    66267316
    66277317char * yy_mm_dd( Time time, char * buf );
     
    66417331
    66427332size_t strftime( char * buf, size_t size, const char * fmt, Time time );
     7333forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
    66437334\end{cfa}
    66447335
     
    66617352
    66627353%\subsection{\texorpdfstring{\protect\lstinline@Clock@}{Clock}}
    6663 \subsection{\texorpdfstring{\LstKeywordStyle{\textmd{Clock}}}{Clock}}
     7354\subsection{\texorpdfstring{\LstBasicStyle{Clock}}{Clock}}
    66647355\label{s:Clock}
    66657356
     
    66677358\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    66687359struct Clock {
    6669         Duration offset;                                        §\C{// for virtual clock: contains offset from real-time}§
    6670         int clocktype;                                          §\C{// implementation only -1 (virtual), CLOCK\_REALTIME}§
     7360        Duration offset; §\C{// for virtual clock: contains offset from real-time}§
     7361        int clocktype; §\C{// implementation only -1 (virtual), CLOCK\_REALTIME}§
    66717362};
    66727363
     
    66757366void ?{}( Clock & clk );
    66767367void ?{}( Clock & clk, Duration adj );
    6677 Duration getRes();
    6678 Time getTimeNsec();                                             §\C{// with nanoseconds}§
    6679 Time getTime();                                                 §\C{// without nanoseconds}§
     7368
     7369Duration getResNsec(); §\C{// with nanoseconds}§
     7370Duration getRes(); §\C{// without nanoseconds}§
     7371
     7372Time getTimeNsec(); §\C{// with nanoseconds}§
     7373Time getTime(); §\C{// without nanoseconds}§
    66807374Time getTime( Clock & clk );
    66817375Time ?()( Clock & clk );
     
    66937387
    66947388\begin{cfa}
    6695 void ?{}( Int * this );                                 §\C{// constructor/destructor}§
     7389void ?{}( Int * this ); §\C{// constructor/destructor}§
    66967390void ?{}( Int * this, Int init );
    66977391void ?{}( Int * this, zero_t );
     
    67027396void ^?{}( Int * this );
    67037397
    6704 Int ?=?( Int * lhs, Int rhs );                  §\C{// assignment}§
     7398Int ?=?( Int * lhs, Int rhs ); §\C{// assignment}§
    67057399Int ?=?( Int * lhs, long int rhs );
    67067400Int ?=?( Int * lhs, unsigned long int rhs );
     
    67197413unsigned long int narrow( Int val );
    67207414
    6721 int ?==?( Int oper1, Int oper2 );               §\C{// comparison}§
     7415int ?==?( Int oper1, Int oper2 ); §\C{// comparison}§
    67227416int ?==?( Int oper1, long int oper2 );
    67237417int ?==?( long int oper2, Int oper1 );
     
    67557449int ?>=?( unsigned long int oper1, Int oper2 );
    67567450
    6757 Int +?( Int oper );                                             §\C{// arithmetic}§
     7451Int +?( Int oper ); §\C{// arithmetic}§
    67587452Int -?( Int oper );
    67597453Int ~?( Int oper );
     
    68377531Int ?>>=?( Int * lhs, mp_bitcnt_t shift );
    68387532
    6839 Int abs( Int oper );                                    §\C{// number functions}§
     7533Int abs( Int oper ); §\C{// number functions}§
    68407534Int fact( unsigned long int N );
    68417535Int gcd( Int oper1, Int oper2 );
     
    68627556#include <gmp>§\indexc{gmp}§
    68637557int main( void ) {
    6864         sout | "Factorial Numbers" | endl;
     7558        sout | "Factorial Numbers";
    68657559        Int fact = 1;
    68667560
    6867         sout | 0 | fact | endl;
     7561        sout | 0 | fact;
    68687562        for ( unsigned int i = 1; i <= 40; i += 1 ) {
    68697563                fact *= i;
    6870                 sout | i | fact | endl;
     7564                sout | i | fact;
    68717565        }
    68727566}
     
    69487642// implementation
    69497643struct Rational {§\indexc{Rational}§
    6950         long int numerator, denominator;        §\C{// invariant: denominator > 0}§
     7644        long int numerator, denominator; §\C{// invariant: denominator > 0}§
    69517645}; // Rational
    69527646
    6953 Rational rational();                                    §\C{// constructors}§
     7647Rational rational(); §\C{// constructors}§
    69547648Rational rational( long int n );
    69557649Rational rational( long int n, long int d );
     
    69577651void ?{}( Rational * r, one_t );
    69587652
    6959 long int numerator( Rational r );               §\C{// numerator/denominator getter/setter}§
     7653long int numerator( Rational r ); §\C{// numerator/denominator getter/setter}§
    69607654long int numerator( Rational r, long int n );
    69617655long int denominator( Rational r );
    69627656long int denominator( Rational r, long int d );
    69637657
    6964 int ?==?( Rational l, Rational r );             §\C{// comparison}§
     7658int ?==?( Rational l, Rational r ); §\C{// comparison}§
    69657659int ?!=?( Rational l, Rational r );
    69667660int ?<?( Rational l, Rational r );
     
    69697663int ?>=?( Rational l, Rational r );
    69707664
    6971 Rational -?( Rational r );                              §\C{// arithmetic}§
     7665Rational -?( Rational r ); §\C{// arithmetic}§
    69727666Rational ?+?( Rational l, Rational r );
    69737667Rational ?-?( Rational l, Rational r );
     
    69757669Rational ?/?( Rational l, Rational r );
    69767670
    6977 double widen( Rational r );                             §\C{// conversion}§
     7671double widen( Rational r ); §\C{// conversion}§
    69787672Rational narrow( double f, long int md );
    69797673
Note: See TracChangeset for help on using the changeset viewer.