Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rc6dc7f2 r48b9b36  
    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 : Sat Jul 13 18:36:18 2019
    14 %% Update Count     : 3876
     13%% Last Modified On : Sun May  6 10:33:53 2018
     14%% Update Count     : 3319
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    7272
    7373% Names used in the document.
    74 \newcommand{\Version}{\input{build/version}}
     74\newcommand{\Version}{\input{../../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 polymorphic routines and types, exceptions, concurrency, and modules.
     148The primary new features include parametric-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{}}~\cite{c++:v1} 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, requiring significant effort and training to incrementally add \CC to a C-based project.
     157\Index*[C++]{\CC{}} 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, all of which requires 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 C, \CFA, and \CC I/O mechanisms, where the programs output the same result.
    163 \begin{center}
     162For example, the following programs compare the \CFA, C, and \CC I/O mechanisms, where the programs output the same result.
     163\begin{cquote}
    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;®§\indexc{sout}§
     180        ®sout | x | y | z | endl;®§\indexc{sout}§
    181181}
    182182\end{cfa}
     
    191191\end{cfa}
    192192\end{tabular}
    193 \end{center}
     193\end{cquote}
    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 
    197196\subsection{Background}
    198197
    199198This document is a programmer reference-manual for the \CFA programming language.
    200 The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of features.
     199The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of each feature.
    201200The manual does not teach programming, \ie how to combine the new constructs to build complex programs.
    202 The 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.
     201A 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.
    203202Implementers should refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
    204203Changes to the syntax and additional features are expected to be included in later revisions.
     
    207206\section{Why fix C?}
    208207
    209 The C programming language is a foundational technology for modern computing with millions of lines of code implementing everything from hobby projects to commercial operating-systems.
     208The 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.
    210209This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
    211210Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    212211For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice.
    213 The 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.
    214 The top 3 rankings over the past 30 years are:
     212The 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.
     213As well, for 30 years, C has been the number 1 and 2 most popular programming language:
    215214\begin{center}
    216 \setlength{\tabcolsep}{10pt}
    217 \begin{tabular}{@{}rccccccc@{}}
    218                 & 2018  & 2013  & 2008  & 2003  & 1998  & 1993  & 1988  \\ \hline
    219 Java    & 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             \\
     215\setlength{\tabcolsep}{1.5ex}
     216\begin{tabular}{@{}r|c|c|c|c|c|c|c@{}}
     217Ranking & 2016  & 2011  & 2006  & 2001  & 1996  & 1991  & 1986          \\
     218\hline
     219Java    & 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                     \\
    222224\end{tabular}
    223225\end{center}
    224226Hence, 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.
    225227Love it or hate it, C has been an important and influential part of computer science for 40 years and its appeal is not diminishing.
    226 Nevertheless, C has many problems and omissions that make it an unacceptable programming language for modern needs.
     228Unfortunately, C has many problems and omissions that make it an unacceptable programming language for modern needs.
    227229
    228230As stated, the goal of the \CFA project is to engineer modern language-features into C in an evolutionary rather than revolutionary way.
     
    234236These 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.
    235237As a result, there is a significant learning curve to move to these languages, and C legacy-code must be rewritten.
    236 These 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 
    238 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 adding modern language-features.
    239 To achieve these goals required a significant engineering exercise, where we had to ``think inside the existing C box''.
    240 Without these significant extension to C, it is unable to cope with the needs of modern programming problems and programmers;
     238These 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
     240The 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.
     241Without significant extension to the C programming language, it is becoming unable to cope with the needs of modern programming problems and programmers;
    241242as a result, it will fade into disuse.
    242243Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern programming language.
     
    254255\begin{lstlisting}
    255256®forall( otype T )® T identity( T val ) { return val; }
    256 int forty_two = identity( 42 ); §\C{// T is bound to int, forty\_two == 42}§
     257int forty_two = identity( 42 );                 §\C{// T is bound to int, forty\_two == 42}§
    257258\end{lstlisting}
    258259% extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions.
     
    282283
    283284double key = 5.0, vals[10] = { /* 10 sorted floating values */ };
    284 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); §\C{// search sorted array}§
     285double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp );      §\C{// search sorted array}§
    285286\end{lstlisting}
    286287which can be augmented simply with a polymorphic, type-safe, \CFA-overloaded wrappers:
     
    291292
    292293forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {
    293         T * result = bsearch( key, arr, size ); §\C{// call first version}§
    294         return result ? result - arr : size; } §\C{// pointer subtraction includes sizeof(T)}§
    295 
    296 double * val = bsearch( 5.0, vals, 10 ); §\C{// selection based on return type}§
     294        T * result = bsearch( key, arr, size ); §\C{// call first version}§
     295        return result ? result - arr : size; }  §\C{// pointer subtraction includes sizeof(T)}§
     296
     297double * val = bsearch( 5.0, vals, 10 );        §\C{// selection based on return type}§
    297298int posn = bsearch( 5.0, vals, 10 );
    298299\end{lstlisting}
     
    306307\begin{lstlisting}
    307308forall( dtype T | sized(T) ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); }
    308 int * ip = malloc(); §\C{// select type and size from left-hand side}§
     309int * ip = malloc();                                    §\C{// select type and size from left-hand side}§
    309310double * dp = malloc();
    310311struct S {...} * sp = malloc();
     
    317318Whereas, \CFA wraps each of these routines into ones with the overloaded name ©abs©:
    318319\begin{cfa}
    319 char ®abs®( char );
    320 extern "C" { int ®abs®( int ); } §\C{// use default C routine for int}§
    321 long int ®abs®( long int );
    322 long long int ®abs®( long long int );
    323 float ®abs®( float );
    324 double ®abs®( double );
    325 long double ®abs®( long double );
    326 float _Complex ®abs®( float _Complex );
    327 double _Complex ®abs®( double _Complex );
    328 long double _Complex ®abs®( long double _Complex );
     320char abs( char );
     321®extern "C" {® int abs( int ); ®}®              §\C{// use default C routine for int}§
     322long int abs( long int );
     323long long int abs( long long int );
     324float abs( float );
     325double abs( double );
     326long double abs( long double );
     327float _Complex abs( float _Complex );
     328double _Complex abs( double _Complex );
     329long double _Complex abs( long double _Complex );
    329330\end{cfa}
    330331The problem is the name clash between the library routine ©abs© and the \CFA names ©abs©.
    331332Hence, names appearing in an ©extern "C"© block have \newterm*{C linkage}.
    332333Then 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.
    333 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.
    334 There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and types.
     334Hence, 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.
     335There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and type.
    335336
    336337This example strongly illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
     
    349350\begin{description}
    350351\item
    351 \Indexc{-std=gnu11}\index{compilation option!-std=gnu11@{©-std=gnu11©}}
    352 The 2011 C standard plus GNU extensions.
    353 \item
    354 \Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]$-fgnu89-inline$}}
    355 Use the traditional GNU semantics for inline routines in C11 mode, which allows inline routines in header files.
     352\Indexc{-std=gnu99}\index{compilation option!-std=gnu99@{©-std=gnu99©}}
     353The 1999 C standard plus GNU extensions.
     354\item
     355\Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]@-fgnu89-inline@}}
     356Use the traditional GNU semantics for inline routines in C99 mode, which allows inline routines in header files.
    356357\end{description}
    357358The following new \CFA options are available:
     
    426427\begin{cfa}
    427428#ifndef __CFORALL__
    428 #include <stdio.h>§\indexc{stdio.h}§ §\C{// C header file}§
     429#include <stdio.h>§\indexc{stdio.h}§    §\C{// C header file}§
    429430#else
    430 #include <fstream>§\indexc{fstream}§ §\C{// \CFA header file}§
     431#include <fstream>§\indexc{fstream}§    §\C{// \CFA header file}§
    431432#endif
    432433\end{cfa}
    433 which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}.
    434 
    435 The \CFA translator has multiple steps.
    436 The following flags control how the tranlator works, the stages run, and printing within a stage.
    437 The 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.
    512 Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    513 \begin{cfa}
    514 int ®`®otype®`® = 3; §\C{// make keyword an identifier}§
    515 double ®`®forall®`® = 3.5;
    516 \end{cfa}
    517 
    518 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.
    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©.
    520 Several 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}
     434which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}.
    540435
    541436
     
    544439Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore}, \eg:
    545440\begin{cfa}
    546 2®_®147®_®483®_®648; §\C{// decimal constant}§
    547 56®_®ul; §\C{// decimal unsigned long constant}§
    548 0®_®377; §\C{// octal constant}§
    549 0x®_®ff®_®ff; §\C{// hexadecimal constant}§
    550 0x®_®ef3d®_®aa5c; §\C{// hexadecimal constant}§
    551 3.141®_®592®_®654; §\C{// floating constant}§
    552 10®_®e®_®+1®_®00; §\C{// floating constant}§
    553 0x®_®ff®_®ff®_®p®_®3; §\C{// hexadecimal floating}§
    554 0x®_®1.ffff®_®ffff®_®p®_®128®_®l; §\C{// hexadecimal floating long constant}§
    555 L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§; §\C{// wide character constant}§
     4412®_®147®_®483®_®648;                                    §\C{// decimal constant}§
     44256®_®ul;                                                                §\C{// decimal unsigned long constant}§
     4430®_®377;                                                                §\C{// octal constant}§
     4440x®_®ff®_®ff;                                                   §\C{// hexadecimal constant}§
     4450x®_®ef3d®_®aa5c;                                               §\C{// hexadecimal constant}§
     4463.141®_®592®_®654;                                              §\C{// floating constant}§
     44710®_®e®_®+1®_®00;                                               §\C{// floating constant}§
     4480x®_®ff®_®ff®_®p®_®3;                                   §\C{// hexadecimal floating}§
     4490x®_®1.ffff®_®ffff®_®p®_®128®_®l;               §\C{// hexadecimal floating long constant}§
     450L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§;     §\C{// wide character constant}§
    556451\end{cfa}
    557452The rules for placement of underscores are:
     
    574469
    575470
     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.
     475Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
     476\begin{cfa}
     477int ®`®otype®`® = 3;                    §\C{// make keyword an identifier}§
     478double ®`®forall®`® = 3.5;
     479\end{cfa}
     480
     481Existing 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©.
     483Several common C header-files with keyword clashes are fixed in the standard \CFA header-library, so there is a seamless programming-experience.
     484
     485\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}
     502\end{figure}
     503
     504
    576505\section{Exponentiation Operator}
    577506
    578507C, \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$.
     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$.
    580509The 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)©.
    581510
    582511As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
    583 Integral 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).
    584 Overflow from large exponents or negative exponents return zero.
    585 Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
    586 \begin{cfa}
    587 sout | 1 ®\® 0 | 1 ®\® 1 | 2 ®\® 8 | -4 ®\® 3 | 5 ®\® 3 | 5 ®\® 32 | 5L ®\® 32 | 5L ®\® 64 | -4 ®\® -3 | -4.0 ®\® -3 | 4.0 ®\® 2.1
    588            | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
    589 1 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
    590 \end{cfa}
    591 Note, ©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.
    592 Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
    593 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
    594 \begin{cfa}
    595 forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
    596 OT ?®\®?( OT ep, unsigned int y );
    597 forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
    598 OT ?®\®?( OT ep, unsigned long int y );
    599 \end{cfa}
    600 The 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 
    611 The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.
    612 (Does not make sense for ©do©-©while©.)
    613 \begin{cfa}
    614 if ( ®int x = f()® ) ... §\C{// x != 0}§
    615 if ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
    616 if ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
    617 if ( ®struct S { int i; } x = { f() }; x.i < 4® ) §\C{// relational expression}§
    618 
    619 while ( ®int x = f()® ) ... §\C{// x != 0}§
    620 while ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
    621 while ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
    622 while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}§
    623 \end{cfa}
    624 Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if©/©while© expression, and the results are combined using the logical ©&&© operator.\footnote{\CC only provides a single declaration always compared not equal to 0.}
    625 The 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 
    630 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
    631 \begin{itemize}
    632 \item
    633 An empty conditional implies ©1©.
    634 \item
    635 The up-to range ©~©\index{~@©~©} means exclusive range [M,N).
    636 \item
    637 The up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
    638 \item
    639 The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M).
    640 \item
    641 The 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
    649 The up-to range uses ©+=© for increment;
    650 \item
    651 The down-to range uses ©-=© for decrement.
    652 \item
    653 The loop index is polymorphic in the type of the start value or comparison value when start is implicitly ©0©.
    654 \end{itemize}
    655 
    656 \begin{figure}
    657 \begin{cquote}
    658 \begin{tabular}{@{}l|l@{}}
    659 \multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
    660 \hline
    661 \begin{cfa}
    662 sout | nlOff;
    663 while ®()® { sout | "empty"; break; } sout | nl;
    664 do { sout | "empty"; break; } while ®()®; sout | nl;
    665 for ®()® { sout | "empty"; break; } sout | nl;
    666 for ( ®0® ) { sout | "A"; } sout | "zero" | nl;
    667 for ( ®1® ) { sout | "A"; } sout | nl;
    668 for ( ®10® ) { sout | "A"; } sout | nl;
    669 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; } sout | nl;
    670 for ( ®10 -~= 1 ~ 2® ) { sout | "C"; } sout | nl;
    671 for ( ®0.5 ~ 5.5® ) { sout | "D"; } sout | nl;
    672 for ( ®5.5 -~ 0.5® ) { sout | "E"; } sout | nl;
    673 for ( ®i; 10® ) { sout | i; } sout | nl;
    674 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; } sout | nl;
    675 for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; } sout | nl;
    676 for ( ®i; 0.5 ~ 5.5® ) { sout | i; } sout | nl;
    677 for ( ®i; 5.5 -~ 0.5® ) { sout | i; } sout | nl;
    678 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; } sout | nl;
    679 for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; } sout | nl;
    680 enum { N = 10 };
    681 for ( ®N® ) { sout | "N"; } sout | nl;
    682 for ( ®i; N® ) { sout | i; } sout | nl;
    683 for ( ®i; N -~ 0® ) { sout | i; } sout | nl;
    684 const int start = 3, comp = 10, inc = 2;
    685 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; } sout | nl;
    686 for ( ®i; 1 ~ @® ) { if ( i > 10 ) break;
    687         sout | i; } sout | nl;
    688 for ( ®i; 10 -~ @® ) { if ( i < 0 ) break;
    689         sout | i; } sout | nl;
    690 for ( ®i; 2 ~ @ ~ 2® ) { if ( i > 10 ) break;
    691         sout | i; } sout | nl;
    692 for ( ®i; 2.1 ~ @ ~ @® ) { if ( i > 10.5 ) break;
    693         sout | i; i += 1.7; } sout | nl;
    694 for ( ®i; 10 -~ @ ~ 2® ) { if ( i < 0 ) break;
    695         sout | i; } sout | nl;
    696 for ( ®i; 12.1 ~ @ ~ @® ) { if ( i < 2.5 ) break;
    697         sout | i; i -= 1.7; } sout | nl;
    698 for ( ®i; 5 : j; -5 ~ @® ) { sout | i | j; } sout | nl;
    699 for ( ®i; 5 : j; -5 -~ @® ) { sout | i | j; } sout | nl;
    700 for ( ®i; 5 : j; -5 ~ @ ~ 2® ) { sout | i | j; } sout | nl;
    701 for ( ®i; 5 : j; -5 -~ @ ~ 2® ) { sout | i | j; } sout | nl;
    702 for ( ®j; -5 ~ @ : i; 5® ) { sout | i | j; } sout | nl;
    703 for ( ®j; -5 -~ @ : i; 5® ) { sout | i | j; } sout | nl;
    704 for ( ®j; -5 ~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
    705 for ( ®j; -5 -~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
    706 for ( ®j; -5 -~ @ ~ 2 : i; 5 : k; 1.5 ~ @® ) {
    707         sout | i | j | k; } sout | nl;
    708 for ( ®j; -5 -~ @ ~ 2 : k; 1.5 ~ @ : i; 5® ) {
    709         sout | i | j | k; } sout | nl;
    710 for ( ®k; 1.5 ~ @ : j; -5 -~ @ ~ 2 : i; 5® ) {
    711         sout | i | j | k; } sout | nl;
    712 \end{cfa}
    713 &
    714 \begin{cfa}
    715 
    716 empty
    717 empty
    718 empty
    719 zero
    720 A
    721 A A A A A A A A A A
    722 B B B B B
    723 C C C C C
    724 D D D D D
    725 E E E E E
    726 0 1 2 3 4 5 6 7 8 9
    727 1 3 5 7 9
    728 10 8 6 4 2
    729 0.5 1.5 2.5 3.5 4.5
    730 5.5 4.5 3.5 2.5 1.5
    731 2 4 6 8 10
    732 10 8 6 4 2
    733 
    734 N N N N N N N N N N
    735 0 1 2 3 4 5 6 7 8 9
    736 10 9 8 7 6 5 4 3 2 1
    737 
    738 3 6 9
    739 
    740 1 2 3 4 5 6 7 8 9 10
    741 
    742 10 9 8 7 6 5 4 3 2 1 0
    743 
    744 2 4 6 8 10
    745 
    746 2.1 3.8 5.5 7.2 8.9
    747 
    748 10 8 6 4 2 0
    749 
    750 12.1 10.4 8.7 7 5.3 3.6
    751 0 -5 1 -4 2 -3 3 -2 4 -1
    752 0 -5 1 -6 2 -7 3 -8 4 -9
    753 0 -5 1 -3 2 -1 3 1 4 3
    754 0 -5 1 -7 2 -9 3 -11 4 -13
    755 0 -5 1 -4 2 -3 3 -2 4 -1
    756 0 -5 1 -6 2 -7 3 -8 4 -9
    757 0 -5 1 -3 2 -1 3 1 4 3
    758 0 -5 1 -7 2 -9 3 -11 4 -13
    759 
    760 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    761 
    762 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    763 
    764 0 -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}
    770 \end{figure}
    771 
    772 
    773 %\section{\texorpdfstring{\protect\lstinline@switch@ Statement}{switch Statement}}
    774 \subsection{\texorpdfstring{\LstKeywordStyle{switch} Statement}{switch Statement}}
    775 
    776 C allows a number of questionable forms for the ©switch© statement:
    777 \begin{enumerate}
    778 \item
    779 By default, the end of a ©case© clause\footnote{
    780 In 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;
    782 to exit a ©switch© statement from a ©case© clause requires explicitly terminating the clause with a transfer statement, most commonly ©break©:
    783 \begin{cfa}
    784 switch ( i ) {
    785   case 1:
    786         ...
    787         // fall-through
    788   case 2:
    789         ...
    790         break;  // exit switch statement
    791 }
    792 \end{cfa}
    793 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:
    794 \begin{cquote}
    795 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    796 \begin{cfa}
    797 switch ( 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 
    811 if ( 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}
    823 In this example, case 2 is always done if case 3 is done.
    824 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.
    825 C also uses fall-through to handle multiple case-values resulting in the same action:
    826 \begin{cfa}
    827 switch ( 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}
    836 However, this situation is handled in other languages without fall-through by allowing a list of case values.
    837 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.
    838 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.
    839 
    840 \item
    841 It is possible to place ©case© clauses on statements nested \emph{within} the body of the ©switch© statement:
    842 \begin{cfa}
    843 switch ( 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}
    858 The problem with this usage is branching into control structures, which is known to cause both comprehension and technical difficulties.
    859 The comprehension problem occurs from the inability to determine how control reaches a particular point due to the number of branches leading to it.
    860 The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
    861 There are no positive arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
    862 Nevertheless, C does have an idiom where this capability is used, known as ``\Index*{Duff's device}''~\cite{Duff83}:
    863 \begin{cfa}
    864 register int n = (count + 7) / 8;
    865 switch ( count % 8 ) {
    866 case 0: do{ *to = *from++;
    867 case 7:         *to = *from++;
    868 case 6:         *to = *from++;
    869 case 5:         *to = *from++;
    870 case 4:         *to = *from++;
    871 case 3:         *to = *from++;
    872 case 2:         *to = *from++;
    873 case 1:         *to = *from++;
    874                 } while ( --n > 0 );
    875 }
    876 \end{cfa}
    877 which unrolls a loop N times (N = 8 above) and uses the ©switch© statement to deal with any iterations not a multiple of N.
    878 While efficient, this sort of special purpose usage is questionable:
    879 \begin{quote}
    880 Disgusting, no? But it compiles and runs just fine. I feel a combination of pride and revulsion at this
    881 discovery.~\cite{Duff83}
    882 \end{quote}
    883 \item
    884 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.
    885 Virtually all programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
    886 The logic for this semantics is that after checking all the ©case© clauses without success, the ©default© clause is selected;
    887 hence, physically placing the ©default© clause at the end of the ©case© clause list matches with this semantics.
    888 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.
    889 
    890 \item
    891 It is possible to place unreachable code at the start of a ©switch© statement, as in:
    892 \begin{cfa}
    893 switch ( 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}
    904 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.
    905 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.
    906 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.
    907 The 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 
    910 Before discussing potential language changes to deal with these problems, it is worth observing that in a typical C program:
    911 \begin{itemize}
    912 \item
    913 the number of ©switch© statements is small,
    914 \item
    915 most ©switch© statements are well formed (\ie no \Index*{Duff's device}),
    916 \item
    917 the ©default© clause is usually written as the last case-clause,
    918 \item
    919 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.
    920 \end{itemize}
    921 These observations put into perspective the \CFA changes to the ©switch©.
    922 \begin{enumerate}
    923 \item
    924 Eliminating default fall-through has the greatest potential for affecting existing code.
    925 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:
    926 \begin{cfa}
    927 case 1:  case 2:  case 3: ...
    928 \end{cfa}
    929 still works.
    930 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.
    931 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:
    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}
    947 Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses;
    948 An implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.
    949 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.
    950 As 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.
    953 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.
    954 \item
    955 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.
    956 Therefore, no change is made for this issue.
    957 \item
    958 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{
    959 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.
    960 Further declarations at the same nesting level as the statement body are disallowed to ensure every transfer into the body is sound.
    961 \begin{cfa}
    962 switch ( 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 
    982 C restricts the ©case© clause of a ©switch© statement to a single value.
    983 For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values.
    984 Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C.
    985 Therefore, 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}
    990 switch ( i ) {
    991   case ®1, 3, 5®:
    992         ...
    993   case ®2, 4, 6®:
    994         ...
    995 }
    996 \end{cfa}
    997 &
    998 \begin{cfa}
    999 switch ( 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}
    1017 In addition, subranges are allowed to specify case values.\footnote{
    1018 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.}
    1019 \begin{cfa}
    1020 switch ( 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}
    1027 Lists of subranges are also allowed.
    1028 \begin{cfa}
    1029 case ®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}}
     512Unsigned 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).
     513Signed 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$.
     514Hence, 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.
     515Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
     516\begin{cfa}
     517sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
     518256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
     519\end{cfa}
     520Parenthesis are necessary for the complex constants or the expresion is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
     521The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available.
     522For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©;
     523for 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}}
    1044527
    1045528While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure.
    1046529Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    1047 To 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.
     530To 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.
    1048531For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    1049532for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
     
    1130613\end{figure}
    1131614
    1132 Both labelled ©continue© and ©break© are a ©goto©\index{goto@©goto©!restricted} restricted in the following ways:
     615Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline@goto@!restricted} restricted in the following ways:
    1133616\begin{itemize}
    1134617\item
     
    1143626With ©goto©, the label is at the end of the control structure, which fails to convey this important clue early enough to the reader.
    1144627Finally, using an explicit target for the transfer instead of an implicit target allows new constructs to be added or removed without affecting existing constructs.
    1145 Otherwise, 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}}
     628The 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
     633C allows a number of questionable forms for the ©switch© statement:
     634\begin{enumerate}
     635\item
     636By default, the end of a ©case© clause\footnote{
     637In 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;
     639to exit a ©switch© statement from a ©case© clause requires explicitly terminating the clause with a transfer statement, most commonly ©break©:
     640\begin{cfa}
     641switch ( i ) {
     642  case 1:
     643        ...
     644        // fall-through
     645  case 2:
     646        ...
     647        break;  // exit switch statement
     648}
     649\end{cfa}
     650The 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}
     654switch ( 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
     668if ( 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}
     680In this example, case 2 is always done if case 3 is done.
     681This 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.
     682C also uses fall-through to handle multiple case-values resulting in the same action:
     683\begin{cfa}
     684switch ( 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}
     693However, this situation is handled in other languages without fall-through by allowing a list of case values.
     694While 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.
     695Hence, 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
     698It is possible to place ©case© clauses on statements nested \emph{within} the body of the ©switch© statement:
     699\begin{cfa}
     700switch ( 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}
     715The problem with this usage is branching into control structures, which is known to cause both comprehension and technical difficulties.
     716The comprehension problem occurs from the inability to determine how control reaches a particular point due to the number of branches leading to it.
     717The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
     718There are no positive arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
     719Nevertheless, C does have an idiom where this capability is used, known as ``\Index*{Duff's device}''~\cite{Duff83}:
     720\begin{cfa}
     721register int n = (count + 7) / 8;
     722switch ( count % 8 ) {
     723case 0: do{ *to = *from++;
     724case 7:         *to = *from++;
     725case 6:         *to = *from++;
     726case 5:         *to = *from++;
     727case 4:         *to = *from++;
     728case 3:         *to = *from++;
     729case 2:         *to = *from++;
     730case 1:         *to = *from++;
     731                } while ( --n > 0 );
     732}
     733\end{cfa}
     734which unrolls a loop N times (N = 8 above) and uses the ©switch© statement to deal with any iterations not a multiple of N.
     735While efficient, this sort of special purpose usage is questionable:
     736\begin{quote}
     737Disgusting, no? But it compiles and runs just fine. I feel a combination of pride and revulsion at this
     738discovery.~\cite{Duff83}
     739\end{quote}
     740\item
     741It is possible to place the ©default© clause anywhere in the list of labelled clauses for a ©switch© statement, rather than only at the end.
     742Virtually all programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
     743The logic for this semantics is that after checking all the ©case© clauses without success, the ©default© clause is selected;
     744hence, physically placing the ©default© clause at the end of the ©case© clause list matches with this semantics.
     745This 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
     748It is possible to place unreachable code at the start of a ©switch© statement, as in:
     749\begin{cfa}
     750switch ( 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}
     761While 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.
     762Furthermore, 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.
     763As 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.
     764The 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
     767Before discussing potential language changes to deal with these problems, it is worth observing that in a typical C program:
     768\begin{itemize}
     769\item
     770the number of ©switch© statements is small,
     771\item
     772most ©switch© statements are well formed (\ie no \Index*{Duff's device}),
     773\item
     774the ©default© clause is usually written as the last case-clause,
     775\item
     776and 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}
     778These observations put into perspective the \CFA changes to the ©switch©.
     779\begin{enumerate}
     780\item
     781Eliminating default fall-through has the greatest potential for affecting existing code.
     782However, 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}
     784case 1:  case 2:  case 3: ...
     785\end{cfa}
     786still works.
     787Nevertheless, reversing the default action would have a non-trivial effect on case actions that compound, such as the above example of processing shell arguments.
     788Therefore, 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}
     804Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses;
     805An implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.
     806An 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.
     807As 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.
     810Hence, 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
     812The 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.
     813Therefore, no change is made for this issue.
     814\item
     815Dealing 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{
     816Essentially, 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.
     817Further declarations at the same nesting level as the statement body are disallowed to ensure every transfer into the body is sound.
     818\begin{cfa}
     819switch ( 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
     838C restricts the ©case© clause of a ©switch© statement to a single value.
     839For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values.
     840Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C.
     841Therefore, 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}
     846switch ( i ) {
     847  case ®1, 3, 5®:
     848        ...
     849  case ®2, 4, 6®:
     850        ...
     851}
     852\end{cfa}
     853&
     854\begin{cfa}
     855switch ( 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}
     873In addition, subranges are allowed to specify case values.\footnote{
     874gcc 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}
     876switch ( 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}
     883Lists of subranges are also allowed.
     884\begin{cfa}
     885case ®1~5, 12~21, 35~42®:
     886\end{cfa}
     887
     888
     889\section{\texorpdfstring{\protect\lstinline@with@ Statement}{with Statement}}
    1150890\label{s:WithStatement}
    1151891
    1152892Grouping 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:
    1153893\begin{cfa}
    1154 struct S { §\C{// aggregate}§
    1155         char c; §\C{// fields}§
     894struct S {                                                                      §\C{// aggregate}§
     895        char c;                                                                 §\C{// fields}§
    1156896        int i;
    1157897        double d;
     
    1162902\begin{cfa}
    1163903void f( S s ) {
    1164         ®s.®c; ®s.®i; ®s.®d; §\C{// access containing fields}§
     904        `s.`c; `s.`i; `s.`d;                                    §\C{// access containing fields}§
    1165905}
    1166906\end{cfa}
     
    1169909\begin{C++}
    1170910struct S {
    1171         char c; §\C{// fields}§
     911        char c;                                                                 §\C{// fields}§
    1172912        int i;
    1173913        double d;
    1174         void f() { §\C{// implicit ``this'' aggregate}§
    1175                 ®this->®c; ®this->®i; ®this->®d; §\C{// access containing fields}§
     914        void f() {                                                              §\C{// implicit ``this'' aggregate}§
     915                `this->`c; `this->`i; `this->`d;        §\C{// access containing fields}§
    1176916        }
    1177917}
    1178918\end{C++}
    1179 Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping.
     919Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]$this->$ because of lexical scoping.
    1180920However, for other aggregate parameters, qualification is necessary:
    1181921\begin{cfa}
    1182922struct T { double m, n; };
    1183 int 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 
    1189 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.
     923int 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
     929To 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.
    1190930Hence, the qualified fields become variables with the side-effect that it is easier to optimizing field references in a block.
    1191931\begin{cfa}
    1192 void f( S & this ) ®with ( this )® { §\C{// with statement}§
    1193         c; i; d; §\C{\color{red}// this.c, this.i, this.d}§
     932void f( S & this ) `with ( this )` {            §\C{// with statement}§
     933        c; i; d;                                                                §\C{\color{red}// this.c, this.i, this.d}§
    1194934}
    1195935\end{cfa}
    1196936with the generality of opening multiple aggregate-parameters:
    1197937\begin{cfa}
    1198 void 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 
    1204 In detail, the ©with© statement has the form:
     938void 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
     944In detail, the @with@ statement has the form:
    1205945\begin{cfa}
    1206946§\emph{with-statement}§:
     
    1217957The difference between parallel and nesting occurs for fields with the same name and type:
    1218958\begin{cfa}
    1219 struct S { int ®i®; int j; double m; } s, w;
    1220 struct T { int ®i®; int k; int m; } t, w;
     959struct S { int `i`; int j; double m; } s, w;
     960struct T { int `i`; int k; int m; } t, w;
    1221961with ( s, t ) {
    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}
    1231 For parallel semantics, both ©s.i© and ©t.i© are visible, so ©i© is ambiguous without qualification;
    1232 for nested semantics, ©t.i© hides ©s.i©, so ©i© implies ©t.i©.
     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}
     971For parallel semantics, both @s.i@ and @t.i@ are visible, so @i@ is ambiguous without qualification;
     972for nested semantics, @t.i@ hides @s.i@, so @i@ implies @t.i@.
    1233973\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.
    1234974Qualification or a cast is used to disambiguate.
    1235975
    1236 There is an interesting problem between parameters and the function-body ©with©, \eg:
    1237 \begin{cfa}
    1238 void ?{}( S & s, int i ) with ( s ) { §\C{// constructor}§
    1239         ®s.i = i;®  j = 3;  m = 5.5; §\C{// initialize fields}§
    1240 }
    1241 \end{cfa}
    1242 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©.
     976There is an interesting problem between parameters and the function-body @with@, \eg:
     977\begin{cfa}
     978void ?{}( S & s, int i ) with ( s ) {           §\C{// constructor}§
     979        `s.i = i;`  j = 3;  m = 5.5;                    §\C{// initialize fields}§
     980}
     981\end{cfa}
     982Here, 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@.
    1243983To solve this problem, parameters are treated like an initialized aggregate:
    1244984\begin{cfa}
     
    1250990and implicitly opened \emph{after} a function-body open, to give them higher priority:
    1251991\begin{cfa}
    1252 void ?{}( S & s, int ®i® ) with ( s ) ®with( §\emph{\color{red}params}§ )® {
    1253         s.i = ®i®; j = 3; m = 5.5;
    1254 }
    1255 \end{cfa}
    1256 Finally, a cast may be used to disambiguate among overload variables in a ©with© expression:
    1257 \begin{cfa}
    1258 with ( w ) { ... } §\C{// ambiguous, same name and no context}§
    1259 with ( (S)w ) { ... } §\C{// unambiguous, cast}§
    1260 \end{cfa}
    1261 and ©with© expressions may be complex expressions with type reference (see Section~\ref{s:References}) to aggregate:
     992void ?{}( S & s, int `i` ) with ( s ) `with( §\emph{\color{red}params}§ )` {
     993        s.i = `i`; j = 3; m = 5.5;
     994}
     995\end{cfa}
     996Finally, a cast may be used to disambiguate among overload variables in a @with@ expression:
     997\begin{cfa}
     998with ( w ) { ... }                                                      §\C{// ambiguous, same name and no context}§
     999with ( (S)w ) { ... }                                           §\C{// unambiguous, cast}§
     1000\end{cfa}
     1001and @with@ expressions may be complex expressions with type reference (see Section~\ref{s:References}) to aggregate:
    12621002% \begin{cfa}
    12631003% struct S { int i, j; } sv;
    1264 % with ( sv ) { §\C{// implicit reference}§
     1004% with ( sv ) {                                                         §\C{// implicit reference}§
    12651005%       S & sr = sv;
    1266 %       with ( sr ) { §\C{// explicit reference}§
     1006%       with ( sr ) {                                                   §\C{// explicit reference}§
    12671007%               S * sp = &sv;
    1268 %               with ( *sp ) { §\C{// computed reference}§
    1269 %                       i = 3; j = 4; §\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}§
     1008%               with ( *sp ) {                                          §\C{// computed reference}§
     1009%                       i = 3; j = 4;                                   §\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}§
    12701010%               }
    1271 %               i = 2; j = 3; §\C{\color{red}// sr.i, sr.j}§
     1011%               i = 2; j = 3;                                           §\C{\color{red}// sr.i, sr.j}§
    12721012%       }
    1273 %       i = 1; j = 2; §\C{\color{red}// sv.i, sv.j}§
     1013%       i = 1; j = 2;                                                   §\C{\color{red}// sv.i, sv.j}§
    12741014% }
    12751015% \end{cfa}
     
    12791019class C {
    12801020        int i, 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}§
     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}§
    12841024        }
    12851025}
     
    12881028\begin{cfa}
    12891029struct S { int i, j; };
    1290 int mem( S & ®this® ) { §\C{// explicit "this" parameter}§
    1291         ®this.®i = 1; §\C{// "this" is not elided}§
     1030int mem( S & ®this® ) {                 §\C{// explicit "this" parameter}§
     1031        ®this.®i = 1;                           §\C{// "this" is not elided}§
    12921032        ®this.®j = 2;
    12931033}
     
    12981038\begin{cfa}
    12991039int mem( S & this ) ®with( this )® { §\C{// with clause}§
    1300         i = 1; §\C{\color{red}// this.i}§
    1301         j = 2; §\C{\color{red}// this.j}§
     1040        i = 1;                                          §\C{\color{red}// this.i}§
     1041        j = 2;                                          §\C{\color{red}// this.j}§
    13021042}
    13031043\end{cfa}
     
    13161056        struct S1 { ... } s1;
    13171057        struct S2 { ... } s2;
    1318         ®with( s1 )® { §\C{// with statement}§
     1058        ®with( s1 )® {                          §\C{// with statement}§
    13191059                // access fields of s1 without qualification
    1320                 ®with s2® { §\C{// nesting}§
     1060                ®with s2® {                             §\C{// nesting}§
    13211061                        // access fields of s1 and s2 without qualification
    13221062                }
     
    13731113Non-local transfer can cause stack unwinding, \ie non-local routine termination, depending on the kind of raise.
    13741114\begin{cfa}
    1375 exception_t E {}; §\C{// exception type}§
     1115exception_t E {};                               §\C{// exception type}§
    13761116void f(...) {
    1377         ... throw E{}; ... §\C{// termination}§
    1378         ... throwResume E{}; ... §\C{// resumption}§
     1117        ... throw E{}; ...                      §\C{// termination}§
     1118        ... throwResume E{}; ...        §\C{// resumption}§
    13791119}
    13801120try {
    13811121        f(...);
    1382 } catch( E e ; §boolean-predicate§ ) {          §\C[8cm]{// termination handler}§
     1122} catch( E e ; §boolean-predicate§ ) {                  §\C[8cm]{// termination handler}§
    13831123        // recover and continue
    1384 } catchResume( E e ; §boolean-predicate§ ) { §\C{// resumption handler}\CRT§
     1124} catchResume( E e ; §boolean-predicate§ ) {    §\C{// resumption handler}\CRT§
    13851125        // repair and return
    13861126} finally {
     
    14421182For example, a routine returning a \Index{pointer} to an array of integers is defined and used in the following way:
    14431183\begin{cfa}
    1444 int ®(*®f®())[®5®]® {...}; §\C{// definition}§
    1445  ... ®(*®f®())[®3®]® += 1; §\C{// usage}§
     1184int ®(*®f®())[®5®]® {...};                              §\C{// definition}§
     1185 ... ®(*®f®())[®3®]® += 1;                              §\C{// usage}§
    14461186\end{cfa}
    14471187Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}).
    1448 While 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}
    1450 In 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}
     1188While attempting to make the two contexts consistent is a laudable goal, it has not worked out in practice.
    14521189
    14531190\CFA provides its own type, variable and routine declarations, using a different syntax.
     
    16351372*x = 3;                 // implicit dereference
    16361373int * ®const® y = (int *)104;
    1637 *y = *x;                        // implicit dereference
     1374*y = *x;                // implicit dereference
    16381375\end{cfa}
    16391376\end{tabular}
     
    16491386\hline
    16501387\begin{cfa}
    1651 lda             r1,100   // load address of x
    1652 ld               r2,(r1)   // load value of x
    1653 lda             r3,104   // load address of y
    1654 st               r2,(r3)   // store x into y
     1388lda             r1,100  // load address of x
     1389ld               r2,(r1)          // load value of x
     1390lda             r3,104  // load address of y
     1391st               r2,(r3)          // store x into y
    16551392\end{cfa}
    16561393&
    16571394\begin{cfa}
    16581395
    1659 ld              r2,(100)   // load value of x
    1660 
    1661 st              r2,(104)   // store x into y
     1396ld              r2,(100)        // load value of x
     1397
     1398st              r2,(104)        // store x into y
    16621399\end{cfa}
    16631400\end{tabular}
     
    16731410\begin{cfa}
    16741411int x, y, ®*® p1, ®*® p2, ®**® p3;
    1675 p1 = ®&®x;    // p1 points to x
    1676 p2 = p1;    // p2 points to x
    1677 p1 = ®&®y;    // p1 points to y
    1678 p3 = &p2;  // p3 points to p2
     1412p1 = ®&®x;              // p1 points to x
     1413p2 = p1;                // p2 points to x
     1414p1 = ®&®y;              // p1 points to y
     1415p3 = &p2;               // p3 points to p2
    16791416\end{cfa}
    16801417&
     
    16871424For example, \Index*{Algol68}~\cite{Algol68} infers pointer dereferencing to select the best meaning for each pointer usage
    16881425\begin{cfa}
    1689 p2 = p1 + x; §\C{// compiler infers *p2 = *p1 + x;}§
     1426p2 = p1 + x;                                    §\C{// compiler infers *p2 = *p1 + x;}§
    16901427\end{cfa}
    16911428Algol68 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.
    1692 Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices.
     1429Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices. 
    16931430
    16941431Rather than inferring dereference, most programming languages pick one implicit dereferencing semantics, and the programmer explicitly indicates the other to resolve address-duality.
    16951432In C, objects of pointer type always manipulate the pointer object's address:
    16961433\begin{cfa}
    1697 p1 = p2; §\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}§
    1698 p2 = p1 + x; §\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}§
     1434p1 = p2;                                                §\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}§
     1435p2 = p1 + x;                                    §\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}§
    16991436\end{cfa}
    17001437even though the assignment to ©p2© is likely incorrect, and the programmer probably meant:
    17011438\begin{cfa}
    1702 p1 = p2; §\C{// pointer address assignment}§
    1703 ®*®p2 = ®*®p1 + x; §\C{// pointed-to value assignment / operation}§
     1439p1 = p2;                                                §\C{// pointer address assignment}§
     1440®*®p2 = ®*®p1 + x;                              §\C{// pointed-to value assignment / operation}§
    17041441\end{cfa}
    17051442The 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©).
     
    17181455\begin{cfa}
    17191456int x, y, ®&® r1, ®&® r2, ®&&® r3;
    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}§
     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}§
    17241461r2 = ((r1 + r2) * (r3 - r1)) / (r3 - 15); §\C{// implicit dereferencing}§
    17251462\end{cfa}
     
    17371474For a \CFA reference type, the cancellation on the left-hand side of assignment leaves the reference as an address (\Index{lvalue}):
    17381475\begin{cfa}
    1739 (&®*®)r1 = &x; §\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}§
     1476(&®*®)r1 = &x;                                  §\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}§
    17401477\end{cfa}
    17411478Similarly, the address of a reference can be obtained for assignment or computation (\Index{rvalue}):
    17421479\begin{cfa}
    1743 (&(&®*®)®*®)r3 = &(&®*®)r2; §\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}§
     1480(&(&®*®)®*®)r3 = &(&®*®)r2;             §\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}§
    17441481\end{cfa}
    17451482Cancellation\index{cancellation!pointer/reference}\index{pointer!cancellation} works to arbitrary depth.
     
    17491486int x, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    17501487                 &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    1751 ***p3 = 3; §\C{// change x}§
    1752 r3 = 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}§
     1488***p3 = 3;                                              §\C{// change x}§
     1489r3 = 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}§
    17581495\end{cfa}
    17591496Furthermore, both types are equally performant, as the same amount of dereferencing occurs for both types.
     
    17621499As for a pointer type, a reference type may have qualifiers:
    17631500\begin{cfa}
    1764 const int cx = 5; §\C{// cannot change cx;}§
    1765 const int & cr = cx; §\C{// cannot change what cr points to}§
    1766 ®&®cr = &cx; §\C{// can change cr}§
    1767 cr = 7; §\C{// error, cannot change cx}§
    1768 int & const rc = x; §\C{// must be initialized}§
    1769 ®&®rc = &x; §\C{// error, cannot change rc}§
    1770 const int & const crc = cx; §\C{// must be initialized}§
    1771 crc = 7; §\C{// error, cannot change cx}§
    1772 ®&®crc = &cx; §\C{// error, cannot change crc}§
     1501const int cx = 5;                                       §\C{// cannot change cx;}§
     1502const int & cr = cx;                            §\C{// cannot change what cr points to}§
     1503®&®cr = &cx;                                            §\C{// can change cr}§
     1504cr = 7;                                                         §\C{// error, cannot change cx}§
     1505int & const rc = x;                                     §\C{// must be initialized}§
     1506®&®rc = &x;                                                     §\C{// error, cannot change rc}§
     1507const int & const crc = cx;                     §\C{// must be initialized}§
     1508crc = 7;                                                        §\C{// error, cannot change cx}§
     1509®&®crc = &cx;                                           §\C{// error, cannot change crc}§
    17731510\end{cfa}
    17741511Hence, 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}:
    17751512\begin{cfa}
    1776 int & const cr = *0; §\C{// where 0 is the int * zero}§
     1513int & const cr = *0;                            §\C{// where 0 is the int * zero}§
    17771514\end{cfa}
    17781515Note, constant reference-types do not prevent \Index{addressing errors} because of explicit storage-management:
     
    17811518cr = 5;
    17821519free( &cr );
    1783 cr = 7; §\C{// unsound pointer dereference}§
     1520cr = 7;                                                         §\C{// unsound pointer dereference}§
    17841521\end{cfa}
    17851522
     
    18061543\begin{cfa}
    18071544int w, x, y, z, & ar[3] = { x, y, z }; §\C{// initialize array of references}§
    1808 &ar[1] = &w; §\C{// change reference array element}§
    1809 typeof( ar[1] ) p; §\C{// (gcc) is int, \ie the type of referenced object}§
    1810 typeof( &ar[1] ) q; §\C{// (gcc) is int \&, \ie the type of reference}§
    1811 sizeof( ar[1] ) == sizeof( int ); §\C{// is true, \ie the size of referenced object}§
    1812 sizeof( &ar[1] ) == sizeof( int *) §\C{// is true, \ie the size of a reference}§
     1545&ar[1] = &w;                                            §\C{// change reference array element}§
     1546typeof( ar[1] ) p;                                      §\C{// (gcc) is int, \ie the type of referenced object}§
     1547typeof( &ar[1] ) q;                                     §\C{// (gcc) is int \&, \ie the type of reference}§
     1548sizeof( ar[1] ) == sizeof( int );       §\C{// is true, \ie the size of referenced object}§
     1549sizeof( &ar[1] ) == sizeof( int *)      §\C{// is true, \ie the size of a reference}§
    18131550\end{cfa}
    18141551
     
    18271564Therefore, for pointer/reference initialization, the initializing value must be an address not a value.
    18281565\begin{cfa}
    1829 int * p = &x; §\C{// assign address of x}§
    1830 ®int * p = x;® §\C{// assign value of x}§
    1831 int & r = x; §\C{// must have address of x}§
     1566int * p = &x;                                           §\C{// assign address of x}§
     1567®int * p = x;®                                          §\C{// assign value of x}§
     1568int & r = x;                                            §\C{// must have address of x}§
    18321569\end{cfa}
    18331570Like 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).
     
    18381575Similarly, 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.
    18391576\begin{cfa}
    1840 int & f( int & r ); §\C{// reference parameter and return}§
    1841 z = f( x ) + f( y ); §\C{// reference operator added, temporaries needed for call results}§
     1577int & f( int & r );                                     §\C{// reference parameter and return}§
     1578z = f( x ) + f( y );                            §\C{// reference operator added, temporaries needed for call results}§
    18421579\end{cfa}
    18431580Within routine ©f©, it is possible to change the argument by changing the corresponding parameter, and parameter ©r© can be locally reassigned within ©f©.
     
    18661603void f( int & r );
    18671604void g( int * p );
    1868 f( 3 );                   g( ®&®3 ); §\C{// compiler implicit generates temporaries}§
    1869 f( x + y );             g( ®&®(x + y) ); §\C{// compiler implicit generates temporaries}§
     1605f( 3 );                   g( ®&®3 );            §\C{// compiler implicit generates temporaries}§
     1606f( x + y );             g( ®&®(x + y) );        §\C{// compiler implicit generates temporaries}§
    18701607\end{cfa}
    18711608Essentially, there is an implicit \Index{rvalue} to \Index{lvalue} conversion in this case.\footnote{
     
    18781615\begin{cfa}
    18791616void f( int i );
    1880 void (* fp)( int ); §\C{// routine pointer}§
    1881 fp = f; §\C{// reference initialization}§
    1882 fp = &f; §\C{// pointer initialization}§
    1883 fp = *f; §\C{// reference initialization}§
    1884 fp(3); §\C{// reference invocation}§
    1885 (*fp)(3); §\C{// pointer invocation}§
     1617void (* fp)( int );                                     §\C{// routine pointer}§
     1618fp = f;                                                         §\C{// reference initialization}§
     1619fp = &f;                                                        §\C{// pointer initialization}§
     1620fp = *f;                                                        §\C{// reference initialization}§
     1621fp(3);                                                          §\C{// reference invocation}§
     1622(*fp)(3);                                                       §\C{// pointer invocation}§
    18861623\end{cfa}
    18871624While 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.
    18881625Instead, a routine object should be referenced by a ©const© reference:
    18891626\begin{cfa}
    1890 ®const® void (®&® fr)( int ) = f; §\C{// routine reference}§
    1891 fr = ... §\C{// error, cannot change code}§
    1892 &fr = ...; §\C{// changing routine reference}§
    1893 fr( 3 ); §\C{// reference call to f}§
    1894 (*fr)(3); §\C{// error, incorrect type}§
     1627®const® void (®&® fr)( int ) = f;       §\C{// routine reference}§
     1628fr = ...                                                        §\C{// error, cannot change code}§
     1629&fr = ...;                                                      §\C{// changing routine reference}§
     1630fr( 3 );                                                        §\C{// reference call to f}§
     1631(*fr)(3);                                                       §\C{// error, incorrect type}§
    18951632\end{cfa}
    18961633because the value of the routine object is a routine literal, \ie the routine code is normally immutable during execution.\footnote{
     
    19051642\begin{itemize}
    19061643\item
    1907 if ©R© is an \Index{rvalue} of type ©T &©$_1\cdots$ ©&©$_r$, where $r \ge 1$ references (©&© symbols), than ©&R© has type ©T ®*®&©$_{\color{red}2}\cdots$ ©&©$_{\color{red}r}$, \ie ©T© pointer with $r-1$ references (©&© symbols).
    1908 
    1909 \item
    1910 if ©L© is an \Index{lvalue} of type ©T &©$_1\cdots$ ©&©$_l$, where $l \ge 0$ references (©&© symbols), than ©&L© has type ©T ®*®&©$_{\color{red}1}\cdots$ ©&©$_{\color{red}l}$, \ie ©T© pointer with $l$ references (©&© symbols).
     1644if ©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
     1647if ©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).
    19111648\end{itemize}
    19121649The following example shows the first rule applied to different \Index{rvalue} contexts:
     
    19141651int x, * px, ** ppx, *** pppx, **** ppppx;
    19151652int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    1916 x = rrrx; §\C[2.0in]{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}§
    1917 px = &rrrx; §\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (\&x)}§
    1918 ppx = &&rrrx; §\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (\&rx)}§
    1919 pppx = &&&rrrx; §\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (\&rrx)}§
    1920 ppppx = &&&&rrrx; §\C{// starting from \&\&\&rrrx, \&\&\&\&rrrx is an rvalue with type int **** (\&rrrx)}§
     1653x = rrrx;               // rrrx is an lvalue with type int &&& (equivalent to x)
     1654px = &rrrx;             // starting from rrrx, &rrrx is an rvalue with type int *&&& (&x)
     1655ppx = &&rrrx;   // starting from &rrrx, &&rrrx is an rvalue with type int **&& (&rx)
     1656pppx = &&&rrrx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (&rrx)
     1657ppppx = &&&&rrrx; // starting from &&&rrrx, &&&&rrrx is an rvalue with type int **** (&rrrx)
    19211658\end{cfa}
    19221659The following example shows the second rule applied to different \Index{lvalue} contexts:
     
    19241661int x, * px, ** ppx, *** pppx;
    19251662int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    1926 rrrx = 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§
     1663rrrx = 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)
    19301667\end{cfa}
    19311668
     
    19401677\begin{cfa}
    19411678int x;
    1942 x + 1; §\C[2.0in]{// lvalue variable (int) converts to rvalue for expression}§
     1679x + 1;                  // lvalue variable (int) converts to rvalue for expression
    19431680\end{cfa}
    19441681An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped.
     
    19501687\begin{cfa}
    19511688int x, &r = x, f( int p );
    1952 x = ®r® + f( ®r® ); §\C{// lvalue reference converts to rvalue}§
     1689x = ®r® + f( ®r® );  // lvalue reference converts to rvalue
    19531690\end{cfa}
    19541691An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped.
     
    19571694lvalue to reference conversion: \lstinline[deletekeywords=lvalue]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
    19581695\begin{cfa}
    1959 int x, &r = ®x®, f( int & p ); §\C{// lvalue variable (int) convert to reference (int \&)}§
    1960 f( ®x® ); §\C{// lvalue variable (int) convert to reference (int \&)}§
     1696int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &)
     1697f( ®x® );               // lvalue variable (int) convert to reference (int &)
    19611698\end{cfa}
    19621699Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.
     
    19681705\begin{cfa}
    19691706int x, & f( int & p );
    1970 f( ®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§
     1707f( ®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 &)
    19721709\end{cfa}
    19731710In both case, modifications to the temporary are inaccessible (\Index{warning}).
     
    21581895in 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:
    21591896\begin{cfa}
    2160 [§\,§] g(); §\C{// no input or output parameters}§
    2161 [ void ] g( void ); §\C{// no input or output parameters}§
     1897[§\,§] g();                                                     §\C{// no input or output parameters}§
     1898[ void ] g( void );                                     §\C{// no input or output parameters}§
    21621899\end{cfa}
    21631900
     
    21771914\begin{cfa}
    21781915typedef int foo;
    2179 int f( int (* foo) ); §\C{// foo is redefined as a parameter name}§
     1916int f( int (* foo) );                           §\C{// foo is redefined as a parameter name}§
    21801917\end{cfa}
    21811918The 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.
     
    21851922C-style declarations can be used to declare parameters for \CFA style routine definitions, \eg:
    21861923\begin{cfa}
    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}§
     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}§
    21891926\end{cfa}
    21901927The 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:
    21911928\begin{cfa}
    21921929#define ptoa( n, d ) int (*n)[ d ]
    2193 int 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 ] )}§
     1930int 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 ] )}§
    21951932\end{cfa}
    21961933Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    22141951        int z;
    22151952        ... x = 0; ... y = z; ...
    2216         ®return;® §\C{// implicitly return x, y}§
     1953        ®return;®                                                       §\C{// implicitly return x, y}§
    22171954}
    22181955\end{cfa}
     
    22241961[ int x, int y ] f() {
    22251962        ...
    2226 } §\C{// implicitly return x, y}§
     1963}                                                                               §\C{// implicitly return x, y}§
    22271964\end{cfa}
    22281965In this case, the current values of ©x© and ©y© are returned to the calling routine just as if a ©return© had been encountered.
     
    22331970[ int x, int y ] f( int, x, int y ) {
    22341971        ...
    2235 } §\C{// implicitly return x, y}§
     1972}                                                                               §\C{// implicitly return x, y}§
    22361973\end{cfa}
    22371974This notation allows the compiler to eliminate temporary variables in nested routine calls.
    22381975\begin{cfa}
    2239 [ int x, int y ] f( int, x, int y ); §\C{// prototype declaration}§
     1976[ int x, int y ] f( int, x, int y );    §\C{// prototype declaration}§
    22401977int a, b;
    22411978[a, b] = f( f( f( a, b ) ) );
     
    22511988as well, parameter names are optional, \eg:
    22521989\begin{cfa}
    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}§
     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}§
    22571994\end{cfa}
    22581995This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
     
    22752012The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg:
    22762013\begin{cfa}
    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}§
     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}§
    22812018\end{cfa}
    22822019While parameter names are optional, \emph{a routine name cannot be specified};
    22832020for example, the following is incorrect:
    22842021\begin{cfa}
    2285 * [ int x ] f () fp; §\C{// routine name "f" is not allowed}§
     2022* [ int x ] f () fp;                                    §\C{// routine name "f" is not allowed}§
    22862023\end{cfa}
    22872024
     
    23062043whereas a named (keyword) call may be:
    23072044\begin{cfa}
    2308 p( z : 3, x : 4, y : 7 );  §\C{// rewrite $\Rightarrow$ p( 4, 7, 3 )}§
     2045p( z : 3, x : 4, y : 7 );       §\C{// rewrite $\Rightarrow$ p( 4, 7, 3 )}§
    23092046\end{cfa}
    23102047Here the order of the arguments is unimportant, and the names of the parameters are used to associate argument values with the corresponding parameters.
     
    23232060For example, the following routine prototypes and definition are all valid.
    23242061\begin{cfa}
    2325 void p( int, int, int ); §\C{// equivalent prototypes}§
     2062void p( int, int, int );                        §\C{// equivalent prototypes}§
    23262063void p( int x, int y, int z );
    23272064void p( int y, int x, int z );
    23282065void p( int z, int y, int x );
    2329 void p( int q, int r, int s ) {} §\C{// match with this definition}§
     2066void p( int q, int r, int s ) {}        §\C{// match with this definition}§
    23302067\end{cfa}
    23312068Forcing matching parameter names in routine prototypes with corresponding routine definitions is possible, but goes against a strong tradition in C programming.
     
    23392076int f( int x, double y );
    23402077
    2341 f( j : 3, i : 4 ); §\C{// 1st f}§
    2342 f( x : 7, y : 8.1 ); §\C{// 2nd f}§
    2343 f( 4, 5 );  §\C{// ambiguous call}§
     2078f( j : 3, i : 4 );                              §\C{// 1st f}§
     2079f( x : 7, y : 8.1 );                    §\C{// 2nd f}§
     2080f( 4, 5 );                                              §\C{// ambiguous call}§
    23442081\end{cfa}
    23452082However, named arguments compound routine resolution in conjunction with conversions:
    23462083\begin{cfa}
    2347 f( i : 3, 5.7 ); §\C{// ambiguous call ?}§
     2084f( i : 3, 5.7 );                                §\C{// ambiguous call ?}§
    23482085\end{cfa}
    23492086Depending on the cost associated with named arguments, this call could be resolvable or ambiguous.
     
    23592096the allowable positional calls are:
    23602097\begin{cfa}
    2361 p(); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
    2362 p( 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
    2363 p( 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
    2364 p( 4, 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 4 )}§
     2098p();                                                    §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
     2099p( 4 );                                                 §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     2100p( 4, 4 );                                              §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     2101p( 4, 4, 4 );                                   §\C{// rewrite $\Rightarrow$ p( 4, 4, 4 )}§
    23652102// empty arguments
    2366 p(  , 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 4 )}§
    2367 p( 4,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 4 )}§
    2368 p( 4, 4,   ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
    2369 p( 4,  ,   ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
    2370 p(  , 4,   ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 3 )}§
    2371 p(  ,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 4 )}§
    2372 p(  ,  ,   ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
     2103p(  , 4, 4 );                                   §\C{// rewrite $\Rightarrow$ p( 1, 4, 4 )}§
     2104p( 4,  , 4 );                                   §\C{// rewrite $\Rightarrow$ p( 4, 2, 4 )}§
     2105p( 4, 4,   );                                   §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     2106p( 4,  ,   );                                   §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     2107p(  , 4,   );                                   §\C{// rewrite $\Rightarrow$ p( 1, 4, 3 )}§
     2108p(  ,  , 4 );                                   §\C{// rewrite $\Rightarrow$ p( 1, 2, 4 )}§
     2109p(  ,  ,   );                                   §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
    23732110\end{cfa}
    23742111Here the missing arguments are inserted from the default values in the parameter list.
     
    23942131Default values may only appear in a prototype versus definition context:
    23952132\begin{cfa}
    2396 void p( int x, int y = 2, int z = 3 ); §\C{// prototype: allowed}§
    2397 void p( int, int = 2, int = 3 ); §\C{// prototype: allowed}§
    2398 void p( int x, int y = 2, int z = 3 ) {} §\C{// definition: not allowed}§
     2133void p( int x, int y = 2, int z = 3 );          §\C{// prototype: allowed}§
     2134void p( int, int = 2, int = 3 );                        §\C{// prototype: allowed}§
     2135void p( int x, int y = 2, int z = 3 ) {}        §\C{// definition: not allowed}§
    23992136\end{cfa}
    24002137The reason for this restriction is to allow separate compilation.
     
    24212158\begin{cfa}
    24222159void p( int x, int y = 2, int z = 3... );
    2423 p( 1, 4, 5, 6, z : 3 ); §\C{// assume p( /* positional */, ... , /* named */ );}§
    2424 p( 1, z : 3, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, ... );}§
     2160p( 1, 4, 5, 6, z : 3 );         §\C{// assume p( /* positional */, ... , /* named */ );}§
     2161p( 1, z : 3, 4, 5, 6 );         §\C{// assume p( /* positional */, /* named */, ... );}§
    24252162\end{cfa}
    24262163The first call is an error because arguments 4 and 5 are actually positional not ellipse arguments;
     
    24522189Furthermore, overloading cannot handle accessing default arguments in the middle of a positional list, via a missing argument, such as:
    24532190\begin{cfa}
    2454 p( 1, /* default */, 5 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 5 )}§
     2191p( 1, /* default */, 5 );               §\C{// rewrite $\Rightarrow$ p( 1, 2, 5 )}§
    24552192\end{cfa}
    24562193
     
    24652202\begin{cfa}
    24662203struct {
    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}§
     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}§
    24732210};
    24742211\end{cfa}
     
    24782215\begin{cfa}
    24792216struct {
    2480         int , , ; §\C{// 3 unnamed fields}§
     2217        int , , ;                               §\C{// 3 unnamed fields}§
    24812218}
    24822219\end{cfa}
     
    25252262        struct T t;
    25262263} s;
    2527 
     2264       
    25282265
    25292266
     
    25722309const unsigned int size = 5;
    25732310int ia[size];
    2574 ... §\C{// assign values to array ia}§
    2575 qsort( ia, size ); §\C{// sort ascending order using builtin ?<?}§
     2311...                                             §\C{// assign values to array ia}§
     2312qsort( ia, size );              §\C{// sort ascending order using builtin ?<?}§
    25762313{
    25772314        ®int ?<?( int x, int y ) { return x > y; }® §\C{// nested routine}§
    2578         qsort( ia, size ); §\C{// sort descending order by local redefinition}§
     2315        qsort( ia, size );      §\C{// sort descending order by local redefinition}§
    25792316}
    25802317\end{cfa}
     
    25842321The following program in undefined in \CFA (and Indexc{gcc})
    25852322\begin{cfa}
    2586 [* [int]( int )] foo() { §\C{// int (* foo())( int )}§
     2323[* [int]( int )] foo() {                §\C{// int (* foo())( int )}§
    25872324        int ®i® = 7;
    25882325        int bar( int p ) {
    2589                 ®i® += 1; §\C{// dependent on local variable}§
    2590                 sout | ®i®;
     2326                ®i® += 1;                               §\C{// dependent on local variable}§
     2327                sout | ®i® | endl;
    25912328        }
    2592         return bar; §\C{// undefined because of local dependence}§
     2329        return bar;                                     §\C{// undefined because of local dependence}§
    25932330}
    25942331int main() {
    2595         * [int]( int ) fp = foo(); §\C{// int (* fp)( int )}§
    2596         sout | fp( 3 );
    2597 }
    2598 \end{cfa}
    2599 because
     2332        * [int]( int ) fp = foo();      §\C{// int (* fp)( int )}§
     2333        sout | fp( 3 ) | endl;
     2334}
     2335\end{cfa}
     2336because 
    26002337
    26012338Currently, there are no \Index{lambda} expressions, \ie unnamed routines because routine names are very important to properly select the correct routine.
     
    26062343In C and \CFA, lists of elements appear in several contexts, such as the parameter list of a routine call.
    26072344\begin{cfa}
    2608 f( ®2, x, 3 + i® ); §\C{// element list}§
     2345f( ®2, x, 3 + i® );                             §\C{// element list}§
    26092346\end{cfa}
    26102347A list of elements is called a \newterm{tuple}, and is different from a \Index{comma expression}.
     
    26232360typedef struct { int quot, rem; } div_t;        §\C[7cm]{// from include stdlib.h}§
    26242361div_t div( int num, int den );
    2625 div_t qr = div( 13, 5 ); §\C{// return quotient/remainder aggregate}§
    2626 printf( "%d %d\n", qr.quot, qr.rem ); §\C{// print quotient/remainder}§
     2362div_t qr = div( 13, 5 );                                        §\C{// return quotient/remainder aggregate}§
     2363printf( "%d %d\n", qr.quot, qr.rem );           §\C{// print quotient/remainder}§
    26272364\end{cfa}
    26282365This approach requires a name for the return type and fields, where \Index{naming} is a common programming-language issue.
     
    26342371For example, consider C's \Indexc{modf} function, which returns the integral and fractional part of a floating value.
    26352372\begin{cfa}
    2636 double modf( double x, double * i ); §\C{// from include math.h}§
    2637 double intp, frac = modf( 13.5, &intp ); §\C{// return integral and fractional components}§
    2638 printf( "%g %g\n", intp, frac ); §\C{// print integral/fractional components}§
     2373double modf( double x, double * i );            §\C{// from include math.h}§
     2374double intp, frac = modf( 13.5, &intp );        §\C{// return integral and fractional components}§
     2375printf( "%g %g\n", intp, frac );                        §\C{// print integral/fractional components}§
    26392376\end{cfa}
    26402377This approach requires allocating storage for the return values, which complicates the call site with a sequence of variable declarations leading to the call.
     
    26632400When 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.
    26642401\begin{cfa}
    2665 void g( int, int ); §\C{// 1}§
    2666 void g( double, double ); §\C{// 2}§
    2667 g( div( 13, 5 ) ); §\C{// select 1}§
    2668 g( modf( 13.5 ) ); §\C{// select 2}§
     2402void g( int, int );                                                     §\C{// 1}§
     2403void g( double, double );                                       §\C{// 2}§
     2404g( div( 13, 5 ) );                                                      §\C{// select 1}§
     2405g( modf( 13.5 ) );                                                      §\C{// select 2}§
    26692406\end{cfa}
    26702407In this case, there are two overloaded ©g© routines.
     
    26752412The previous examples can be rewritten passing the multiple returned-values directly to the ©printf© function call.
    26762413\begin{cfa}
    2677 [ int, int ] div( int x, int y ); §\C{// from include stdlib}§
    2678 printf( "%d %d\n", div( 13, 5 ) ); §\C{// print quotient/remainder}§
    2679 
    2680 [ double, double ] modf( double x ); §\C{// from include math}§
    2681 printf( "%g %g\n", modf( 13.5 ) ); §\C{// print integral/fractional components}§
     2414[ int, int ] div( int x, int y );                       §\C{// from include stdlib}§
     2415printf( "%d %d\n", div( 13, 5 ) );                      §\C{// print quotient/remainder}§
     2416
     2417[ double, double ] modf( double x );            §\C{// from include math}§
     2418printf( "%g %g\n", modf( 13.5 ) );                      §\C{// print integral/fractional components}§
    26822419\end{cfa}
    26832420This 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.
     
    26892426\begin{cfa}
    26902427int quot, rem;
    2691 [ quot, rem ] = div( 13, 5 ); §\C{// assign multiple variables}§
    2692 printf( "%d %d\n", quot, rem ); §\C{// print quotient/remainder}\CRT§
     2428[ quot, rem ] = div( 13, 5 );                           §\C{// assign multiple variables}§
     2429printf( "%d %d\n", quot, rem );                         §\C{// print quotient/remainder}\CRT§
    26932430\end{cfa}
    26942431Here, the multiple return-values are matched in much the same way as passing multiple return-values to multiple parameters in a call.
     
    26962433
    26972434\subsection{Expressions}
    2698 
    2699 % Change order of expression evaluation.
    2700 % http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0145r2.pdf
    27012435
    27022436Multiple-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.
     
    27192453In \CFA, it is possible to overcome this restriction by declaring a \newterm{tuple variable}.
    27202454\begin{cfa}
    2721 [int, int] ®qr® = div( 13, 5 ); §\C{// initialize tuple variable}§
    2722 printf( "%d %d\n", ®qr® ); §\C{// print quotient/remainder}§
     2455[int, int] ®qr® = div( 13, 5 );                 §\C{// initialize tuple variable}§
     2456printf( "%d %d\n", ®qr® );                              §\C{// print quotient/remainder}§
    27232457\end{cfa}
    27242458It is now possible to match the multiple return-values to a single variable, in much the same way as \Index{aggregation}.
     
    27262460One way to access the individual components of a tuple variable is with assignment.
    27272461\begin{cfa}
    2728 [ quot, rem ] = qr; §\C{// assign multiple variables}§
     2462[ quot, rem ] = qr;                                             §\C{// assign multiple variables}§
    27292463\end{cfa}
    27302464
     
    27492483[int, double] * p;
    27502484
    2751 int y = x.0; §\C{// access int component of x}§
    2752 y = f().1; §\C{// access int component of f}§
    2753 p->0 = 5; §\C{// access int component of tuple pointed-to by p}§
    2754 g( x.1, x.0 ); §\C{// rearrange x to pass to g}§
    2755 double z = [ x, f() ].0.1; §\C{// access second component of first component of tuple expression}§
     2485int y = x.0;                                                    §\C{// access int component of x}§
     2486y = f().1;                                                              §\C{// access int component of f}§
     2487p->0 = 5;                                                               §\C{// access int component of tuple pointed-to by p}§
     2488g( x.1, x.0 );                                                  §\C{// rearrange x to pass to g}§
     2489double z = [ x, f() ].0.1;                              §\C{// access second component of first component of tuple expression}§
    27562490\end{cfa}
    27572491Tuple-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.
     
    28202554double y;
    28212555[int, double] z;
    2822 [y, x] = 3.14; §\C{// mass assignment}§
     2556[y, x] = 3.14;                                                  §\C{// mass assignment}§
    28232557[x, y] = z;                                                         §\C{// multiple assignment}§
    28242558z = 10;                                                         §\C{// mass assignment}§
    2825 z = [x, y]; §\C{// multiple assignment}§
     2559z = [x, y];                                                             §\C{// multiple assignment}§
    28262560\end{cfa}
    28272561Let $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.
     
    28672601        double c, d;
    28682602        [ void ] f( [ int, int ] );
    2869         f( [ c, a ] = [ b, d ] = 1.5 ); §\C{// assignments in parameter list}§
     2603        f( [ c, a ] = [ b, d ] = 1.5 );  // assignments in parameter list
    28702604\end{cfa}
    28712605The 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.
     
    28802614\begin{cfa}
    28812615struct S;
    2882 void ?{}(S *); §\C{// (1)}§
    2883 void ?{}(S *, int); §\C{// (2)}§
    2884 void ?{}(S * double); §\C{// (3)}§
    2885 void ?{}(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}§
     2616void ?{}(S *);         // (1)
     2617void ?{}(S *, int);    // (2)
     2618void ?{}(S * double);  // (3)
     2619void ?{}(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
    28902624\end{cfa}
    28912625In 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)©.
     
    29282662A member-access tuple may be used anywhere a tuple can be used, \eg:
    29292663\begin{cfa}
    2930 s.[ y, z, x ] = [ 3, 3.2, 'x' ]; §\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}§
    2931 f( s.[ y, z ] ); §\C{// equivalent to f( s.y, s.z )}§
     2664s.[ y, z, x ] = [ 3, 3.2, 'x' ];                §\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}§
     2665f( s.[ y, z ] );                                                §\C{// equivalent to f( s.y, s.z )}§
    29322666\end{cfa}
    29332667Note, the fields appearing in a record-field tuple may be specified in any order;
     
    29392673void f( double, long );
    29402674
    2941 f( x.[ 0, 3 ] ); §\C{// f( x.0, x.3 )}§
    2942 x.[ 0, 1 ] = x.[ 1, 0 ]; §\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}§
     2675f( x.[ 0, 3 ] );                                                §\C{// f( x.0, x.3 )}§
     2676x.[ 0, 1 ] = x.[ 1, 0 ];                                §\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}§
    29432677[ long, int, long ] y = x.[ 2, 0, 2 ];
    29442678\end{cfa}
     
    29572691\begin{cfa}
    29582692[ int, float, double ] f();
    2959 [ double, float ] x = f().[ 2, 1 ]; §\C{// f() called once}§
     2693[ double, float ] x = f().[ 2, 1 ];             §\C{// f() called once}§
    29602694\end{cfa}
    29612695
     
    29702704That 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.
    29712705\begin{cfa}
    2972 int f(); §\C{// (1)}§
    2973 double f(); §\C{// (2)}§
    2974 
    2975 f(); §\C{// ambiguous - (1),(2) both equally viable}§
    2976 (int)f(); §\C{// choose (2)}§
     2706int f();     // (1)
     2707double f();  // (2)
     2708
     2709f();       // ambiguous - (1),(2) both equally viable
     2710(int)f();  // choose (2)
    29772711\end{cfa}
    29782712Since casting is a fundamental operation in \CFA, casts need to be given a meaningful interpretation in the context of tuples.
     
    29822716void g();
    29832717
    2984 (void)f(); §\C{// valid, ignore results}§
    2985 (int)g(); §\C{// invalid, void cannot be converted to int}§
     2718(void)f();  // valid, ignore results
     2719(int)g();   // invalid, void cannot be converted to int
    29862720
    29872721struct A { int x; };
    2988 (struct A)f(); §\C{// invalid, int cannot be converted to A}§
     2722(struct A)f();  // invalid, int cannot be converted to A
    29892723\end{cfa}
    29902724In C, line 4 is a valid cast, which calls ©f© and discards its result.
     
    30022736        [int, [int, int], int] g();
    30032737
    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}§
     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
    30092743\end{cfa}
    30102744
     
    30662800void f([int, int], int, int);
    30672801
    3068 f([0, 0], 0, 0); §\C{// no cost}§
    3069 f(0, 0, 0, 0); §\C{// cost for structuring}§
    3070 f([0, 0,], [0, 0]); §\C{// cost for flattening}§
    3071 f([0, 0, 0], 0); §\C{// cost for flattening and structuring}§
     2802f([0, 0], 0, 0);    // no cost
     2803f(0, 0, 0, 0);      // cost for structuring
     2804f([0, 0,], [0, 0]); // cost for flattening
     2805f([0, 0, 0], 0);    // cost for flattening and structuring
    30722806\end{cfa}
    30732807
     
    31322866[ unsigned int, char ]
    31332867[ double, double, double ]
    3134 [ * int, int * ] §\C{// mix of CFA and ANSI}§
     2868[ * int, int * ]                §\C{// mix of CFA and ANSI}§
    31352869[ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    31362870\end{cfa}
     
    31392873Examples of declarations using tuple types are:
    31402874\begin{cfa}
    3141 [ int, int ] x; §\C{// 2 element tuple, each element of type int}§
    3142 * [ char, char ] y; §\C{// pointer to a 2 element tuple}§
     2875[ int, int ] x;                 §\C{// 2 element tuple, each element of type int}§
     2876* [ char, char ] y;             §\C{// pointer to a 2 element tuple}§
    31432877[ [ int, int ] ] z ([ int, int ]);
    31442878\end{cfa}
     
    31572891[ int, int ] w1;
    31582892[ int, int, int ] w2;
    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}§
     2893[ void ] f (int, int, int); /* three input parameters of type int */
     2894[ void ] g ([ int, int, int ]); /* 3 element tuple as input */
    31612895f( [ 1, 2, 3 ] );
    31622896f( w1, 3 );
     
    32382972[ int, int, int, int ] w = [ 1, 2, 3, 4 ];
    32392973int x = 5;
    3240 [ x, w ] = [ w, x ]; §\C{// all four tuple coercions}§
     2974[ x, w ] = [ w, x ];            §\C{// all four tuple coercions}§
    32412975\end{cfa}
    32422976Starting on the right-hand tuple in the last assignment statement, w is opened, producing a tuple of four values;
     
    33263060both these examples produce indeterminate results:
    33273061\begin{cfa}
    3328 f( 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}§
     3062f( 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}§
    33303064\end{cfa}
    33313065
     
    33493083
    33503084
    3351 \section{Stream I/O Library}
    3352 \label{s:StreamIOLibrary}
    3353 \index{input/output stream library}
    3354 \index{stream library}
    3355 
    3356 The 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.
    3357 Stream I/O can be implicitly or explicitly formatted.
    3358 Implicit formatting means \CFA selects the output or input format for values that match with the type of a variable.
    3359 Explicit 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.
    3361 Specifically:
    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
    3370 Format manipulators in \CFA have local effect, whereas \CC have global effect, except ©setw©.
    3371 Hence, it is common programming practice to toggle manipulators on and then back to the default to prevent downstream side-effects.
    3372 Without 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}
    3377 The \CFA header file for the I/O library is \Indexc{fstream.hfa}.
    3378 
    3379 For implicit formatted output, the common case is printing a series of variables separated by whitespace.
     3085\section{I/O Library}
     3086\label{s:IOLibrary}
     3087\index{input/output library}
     3088
     3089The 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.
     3090The approach combines ideas from \CC and Python.
     3091The \CFA header file for the I/O library is \Indexc{fstream}.
     3092
     3093The common case is printing out a sequence of variables separated by whitespace.
    33803094\begin{cquote}
    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}}   \\
     3095\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
     3096\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
    33833097\begin{cfa}
    33843098int x = 1, y = 2, z = 3;
    3385 sout | x ®|® y ®|® z;
     3099sout | x ®|® y ®|® z | endl;
    33863100\end{cfa}
    33873101&
     
    33893103
    33903104cout << x ®<< " "® << y ®<< " "® << z << endl;
    3391 \end{cfa}
    3392 &
    3393 \begin{cfa}
    3394 x = 1;  y = 2;  z = 3
    3395 print( x, y, z )
    33963105\end{cfa}
    33973106\\
     
    34013110&
    34023111\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3403 1® ®2® ®3
    3404 \end{cfa}
    3405 &
    3406 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3407 1® ®2® ®3
     31121 2 3
    34083113\end{cfa}
    34093114\end{tabular}
    34103115\end{cquote}
    3411 The \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.
    3412 Similar simplification occurs for \Index{tuple} I/O, which flattens the tuple and prints each value separated by ``\lstinline[showspaces=true]@, @''.
     3116The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators.
     3117Similar simplification occurs for \Index{tuple} I/O, which prints all tuple values separated by ``\lstinline[showspaces=true]@, @''.
    34133118\begin{cfa}
    34143119[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    3415 sout | t1 | t2; §\C{// print tuples}§
     3120sout | t1 | t2 | endl;                                  §\C{// print tuples}§
    34163121\end{cfa}
    34173122\begin{cfa}[showspaces=true,aboveskip=0pt]
    341831231®, ®2®, ®3 4®, ®5®, ®6
    34193124\end{cfa}
    3420 Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority \emph{overloadable} operator, other than assignment.
     3125Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment.
    34213126Therefore, fewer output expressions require parenthesis.
    34223127\begin{cquote}
     
    34253130&
    34263131\begin{cfa}
    3427 sout | x * 3 | y + 1 | z << 2 | x == y | ®(®x | y®)® | ®(®x || y®)® | ®(®x > z ? 1 : 2®)®;
     3132sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
    34283133\end{cfa}
    34293134\\
     
    34313136&
    34323137\begin{cfa}
    3433 cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << ®(®x | y®)® << ®(®x || y®)® << ®(®x > z ? 1 : 2®)® << endl;
     3138cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
    34343139\end{cfa}
    34353140\\
     
    34403145\end{tabular}
    34413146\end{cquote}
    3442 Input and output use a uniform operator, ©|©, rather than separate operators, as in ©>>© and ©<<© for \CC.
    3443 There 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 
    3445 For 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]
    3449 int 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]
    3456 sin | x | y | z;
    3457 \end{cfa}
    3458 &
    3459 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
    3460 cin >> x >> y >> z;
    3461 \end{cfa}
    3462 &
    3463 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
    3464 x = 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 
     3147There 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.
    34873148
    34883149
    34893150\subsection{Implicit Separator}
    34903151
    3491 The \Index{implicit separator}\index{I/O!separator} character (space/blank) is a separator not a terminator for output.
     3152The \Index{implicit separator}\index{I/O!separator} character (space/blank) is a separator not a terminator.
    34923153The rules for implicitly adding the separator are:
    34933154\begin{enumerate}
     
    34953156A separator does not appear at the start or end of a line.
    34963157\begin{cfa}[belowskip=0pt]
    3497 sout | 1 | 2 | 3;
     3158sout | 1 | 2 | 3 | endl;
    34983159\end{cfa}
    34993160\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    35043165A separator does not appear before or after a character literal or variable.
    35053166\begin{cfa}
    3506 sout | '1' | '2' | '3';
     3167sout | '1' | '2' | '3' | endl;
    35073168123
    35083169\end{cfa}
    35093170
    35103171\item
    3511 A 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}
    3513 sout | 1 | "" | 2 | "" | 3;
     3172A separator does not appear before or after a null (empty) C string.
     3173\begin{cfa}
     3174sout | 1 | "" | 2 | "" | 3 | endl;
    35143175123
    35153176\end{cfa}
     3177which is a local mechanism to disable insertion of the separator character.
     3178
     3179\item
     3180A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$£¥¡¿«@
     3181%$
     3182\begin{cfa}[mathescape=off]
     3183sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
     3184                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
     3185\end{cfa}
     3186%$
     3187\begin{cfa}[mathescape=off,basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
     3188x ®(®1 x ®[®2 x ®{®3 x ®=®4 x ®$®5 x ®£®6 x ®¥®7 x ®¡®8 x ®¿®9 x ®«®10
     3189\end{cfa}
     3190%$
     3191where \lstinline[basicstyle=\tt]@¡¿@ are inverted opening exclamation and question marks, and \lstinline[basicstyle=\tt]@«@ is an opening citation mark.
    35163192
    35173193\item
    35183194{\lstset{language=CFA,deletedelim=**[is][]{¢}{¢}}
    3519 A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[basicstyle=\tt]@,.;!?)]}%¢»@, where \lstinline[basicstyle=\tt]@»@ is a closing citation mark.
     3195A seperator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[basicstyle=\tt]@,.;!?)]}%¢»@
    35203196\begin{cfa}[belowskip=0pt]
    35213197sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    3522                 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
     3198                | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;
    35233199\end{cfa}
    35243200\begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
    352532011®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7§\color{red}\textcent§ x 8®»® x 9®)® x 10®]® x 11®}® x
    35263202\end{cfa}}%
    3527 
    3528 \item
    3529 A separator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$£¥¡¿«@, where \lstinline[basicstyle=\tt]@¡¿@ are inverted opening exclamation and question marks, and \lstinline[basicstyle=\tt]@«@ is an opening citation mark.
    3530 %$
    3531 \begin{cfa}[mathescape=off]
    3532 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
    3533                 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
    3534 \end{cfa}
    3535 %$
    3536 \begin{cfa}[mathescape=off,basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
    3537 x ®(®1 x ®[®2 x ®{®3 x ®=®4 x ®$®5 x ®£®6 x ®¥®7 x ®¡®8 x ®¿®9 x ®«®10
    3538 \end{cfa}
    3539 %$
    3540 
    3541 \item
    3542 A seperator does not appear before/after a C string starting/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]@`'": \t\v\f\r\n@
     3203where \lstinline[basicstyle=\tt]@»@ is a closing citation mark.
     3204
     3205\item
     3206A 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@
    35433207\begin{cfa}[belowskip=0pt]
    3544 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx";
     3208sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;
    35453209\end{cfa}
    35463210\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     
    35513215If a space is desired before or after one of the special string start/end characters, simply insert a space.
    35523216\begin{cfa}[belowskip=0pt]
    3553 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;
     3217sout | "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;
    35543218\end{cfa}
    35553219\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     
    35593223
    35603224
    3561 \subsection{Separation Manipulators}
    3562 
    3563 The following \Index{manipulator}s control \Index{implicit output separation}.
    3564 The effect of these manipulators is global for an output stream (except ©sepOn© and ©sepOff©).
     3225\subsection{Manipulator}
     3226
     3227The following \CC-style \Index{manipulator}s and routines control implicit seperation.
    35653228\begin{enumerate}
    35663229\item
    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.
     3230Routines \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.
    35683231The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    35693232\begin{cfa}[mathescape=off,belowskip=0pt]
    3570 sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§
    3571 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"";
     3233sepSet( sout, ", $" );                                          §\C{// set separator from " " to ", \$"}§
     3234sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl;
    35723235\end{cfa}
    35733236%$
     
    35773240%$
    35783241\begin{cfa}[belowskip=0pt]
    3579 sepSet( sout, " " ); §\C{// reset separator to " "}§
    3580 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"";
     3242sepSet( sout, " " );                                            §\C{// reset separator to " "}§
     3243sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
    35813244\end{cfa}
    35823245\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    35853248©sepGet© can be used to store a separator and then restore it:
    35863249\begin{cfa}[belowskip=0pt]
    3587 char store[®sepSize®]; §\C{// sepSize is the maximum separator size}§
    3588 strcpy( store, sepGet( sout ) ); §\C{// copy current separator}§
    3589 sepSet( sout, "_" ); §\C{// change separator to underscore}§
    3590 sout | 1 | 2 | 3;
     3250char store[®sepSize®];                                          §\C{// sepSize is the maximum separator size}§
     3251strcpy( store, sepGet( sout ) );                          §\C{// copy current separator}§
     3252sepSet( sout, "_" );                                            §\C{// change separator to underscore}§
     3253sout | 1 | 2 | 3 | endl;
    35913254\end{cfa}
    35923255\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    35943257\end{cfa}
    35953258\begin{cfa}[belowskip=0pt]
    3596 sepSet( sout, store ); §\C{// change separator back to original}§
    3597 sout | 1 | 2 | 3;
     3259sepSet( sout, store );                                          §\C{// change separator back to original}§
     3260sout | 1 | 2 | 3 | endl;
    35983261\end{cfa}
    35993262\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    36023265
    36033266\item
    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.
     3267Routine \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.
    36053268The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    36063269\begin{cfa}[belowskip=0pt]
    3607 sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§
    3608 sout | t1 | t2 | " \"" | ®sepTuple® | "\"";
     3270sepSetTuple( sout, " " );                                       §\C{// set tuple separator from ", " to " "}§
     3271sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl;
    36093272\end{cfa}
    36103273\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    36123275\end{cfa}
    36133276\begin{cfa}[belowskip=0pt]
    3614 sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§
    3615 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"";
     3277sepSetTuple( sout, ", " );                                      §\C{// reset tuple separator to ", "}§
     3278sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
    36163279\end{cfa}
    36173280\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    36213284
    36223285\item
    3623 \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} toggle printing the separator.
     3286Manipulators \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.
    36243287\begin{cfa}[belowskip=0pt]
    3625 sout | sepDisable | 1 | 2 | 3; §\C{// turn off implicit separator}§
     3288sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// globally turn off implicit separator}§
    36263289\end{cfa}
    36273290\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36293292\end{cfa}
    36303293\begin{cfa}[belowskip=0pt]
    3631 sout | sepEnable | 1 | 2 | 3; §\C{// turn on implicit separator}§
     3294sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// globally turn on implicit separator}§
    36323295\end{cfa}
    36333296\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36363299
    36373300\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.
     3301Manipulators \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.
    36393302\begin{cfa}[belowskip=0pt]
    3640 sout | 1 | sepOff | 2 | 3; §\C{// turn off implicit separator for the next item
     3303sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// locally turn off implicit separator
    36413304\end{cfa}
    36423305\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36443307\end{cfa}
    36453308\begin{cfa}[belowskip=0pt]
    3646 sout | sepDisable | 1 | sepOn | 2 | 3; §\C{// turn on implicit separator for the next item
     3309sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator
    36473310\end{cfa}
    36483311\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36513314The tuple separator also responses to being turned on and off.
    36523315\begin{cfa}[belowskip=0pt]
    3653 sout | t1 | sepOff | t2; §\C{// turn off implicit separator for the next item
     3316sout | t1 | sepOff | t2 | endl;                         §\C{// locally turn on/off implicit separator
    36543317\end{cfa}
    36553318\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36593322use ©sep© to accomplish this functionality.
    36603323\begin{cfa}[belowskip=0pt]
    3661 sout | sepOn | 1 | 2 | 3 | sepOn; §\C{// sepOn does nothing at start/end of line}§
     3324sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       §\C{// sepOn does nothing at start/end of line}§
    36623325\end{cfa}
    36633326\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36653328\end{cfa}
    36663329\begin{cfa}[belowskip=0pt]
    3667 sout | sep | 1 | 2 | 3 | sep ; §\C{// use sep to print separator at start/end of line}§
     3330sout | sep | 1 | 2 | 3 | sep | endl ;           §\C{// use sep to print separator at start/end of line}§
    36683331\end{cfa}
    36693332\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    36703333® ®1 2 3® ®
    3671 \end{cfa}
    3672 \end{enumerate}
    3673 
    3674 
    3675 \subsection{Newline Manipulators}
    3676 
    3677 The following \Index{manipulators} control \Index{newline separation} for input and output.
    3678 
    3679 For 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}
    3688 For example, in:
    3689 \begin{cfa}
    3690 sin | i | ®nl® | j;
    3691 1 ®2®
    3692 3
    3693 \end{cfa}
    3694 variable ©i© is assigned 1, the 2 is skipped, and variable ©j© is assigned 3.
    3695 
    3696 For output:
    3697 \begin{enumerate}[parsep=0pt]
    3698 \item
    3699 \Indexc{nl}\index{manipulator!nl@©nl©} inserts a newline.
    3700 \begin{cfa}
    3701 sout | nl; §\C{// only print newline}§
    3702 sout | 2; §\C{// implicit newline}§
    3703 sout | 3 | nl | 4 | nl; §\C{// terminating nl merged with implicit newline}§
    3704 sout | 5 | nl | nl; §\C{// again terminating nl merged with implicit newline}§
    3705 sout | 6; §\C{// implicit newline}§
    3706 
    3707 2
    3708 3
    3709 4
    3710 5
    3711 
    3712 6
    3713 \end{cfa}
    3714 Note, 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 
    3724 The 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]
    3729 sout | bin( 0 ) | bin( 27HH ) | bin( 27H ) | bin( 27 ) | bin( 27L );
    3730 0b0 0b11011 0b11011 0b11011 0b11011
    3731 sout | bin( -27HH ) | bin( -27H ) | bin( -27 ) | bin( -27L );
    3732 0b11100101 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]
    3738 sout | oct( 0 ) | oct( 27HH ) | oct( 27H ) | oct( 27 ) | oct( 27L );
    3739 0 033 033 033 033
    3740 sout | oct( -27HH ) | oct( -27H ) | oct( -27 ) | oct( -27L );
    3741 0345 0177745 037777777745 01777777777777777777745
    3742 \end{cfa}
    3743 Note, 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]
    3748 sout | hex( 0 ) | hex( 27HH ) | hex( 27H ) | hex( 27 ) | hex( 27L );
    3749 0 0x1b 0x1b 0x1b 0x1b
    3750 sout | hex( -27HH ) | hex( -27H ) | hex( -27 ) | hex( -27L );
    3751 0xe5 0xffe5 0xffffffe5 0xffffffffffffffe5
    3752 
    3753 sout | hex( 0.0 ) | hex( 27.5F ) | hex( 27.5 ) | hex( 27.5L );
    3754 0x0.p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
    3755 sout | 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.
    3761 Default is 6 digits of precision.
    3762 \begin{cfa}[belowskip=0pt]
    3763 sout | sci( 0.0 ) | sci( 27.5 ) | sci( -27.5 );
    3764 0.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]
    3770 sout | upcase( bin( 27 ) ) | upcase( hex( 27 ) ) | upcase( 27.5e-10 ) | upcase( hex( 27.5 ) );
    3771 0®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©.
    3776 Printing the base is the default.
    3777 \begin{cfa}[belowskip=0pt]
    3778 sout | nobase( bin( 27 ) ) | nobase( oct( 27 ) ) | nobase( hex( 27 ) );
    3779 11011 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.
    3784 Printing a decimal point is the default, if there are no fractional digits.
    3785 \begin{cfa}[belowskip=0pt]
    3786 sout | 0. | nodp( 0. ) | 27.0 | nodp( 27.0 ) | nodp( 27.5 );
    3787 0.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]
    3793 sout | 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 )©
    3799 For all types, ©minimum© is the minimum number of printed characters.
    3800 If the value is shorter than the minimum, it is padded on the right with spaces.
    3801 \begin{cfa}[belowskip=0pt]
    3802 sout | wd( 4, 34) | wd( 3, 34 ) | wd( 2, 34 );
    3803 sout | wd( 10, 4.) | wd( 9, 4. ) | wd( 8, 4. );
    3804 sout | 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}
    3811 If the value is larger, it is printed without truncation, ignoring the ©minimum©.
    3812 \begin{cfa}[belowskip=0pt]
    3813 sout | wd( 4, 34567 ) | wd( 3, 34567 ) | wd( 2, 34567 );
    3814 sout | wd( 4, 3456. ) | wd( 3, 3456. ) | wd( 2, 3456. );
    3815 sout | wd( 4, "abcde" ) | wd( 3, "abcde" ) | wd( 2,"abcde" );
    3816 \end{cfa}
    3817 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3818 3456®7® 345®67® 34®567®
    3819 3456®.® 345®6.® 34®56.®
    3820 abcd®e® abc®de® ab®cde®
    3821 \end{cfa}
    3822 
    3823 For integer types, ©precision© is the minimum number of printed digits.
    3824 If the value is shorter, it is padded on the left with leading zeros.
    3825 \begin{cfa}[belowskip=0pt]
    3826 sout | 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}
    3831 If the value is larger, it is printed without truncation, ignoring the ©precision©.
    3832 \begin{cfa}[belowskip=0pt]
    3833 sout | wd( 4,1, 3456 ) | wd( 8,2, 3456 ) | wd( 10,3, 3456 );
    3834 \end{cfa}
    3835 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3836 3456     3456       3456
    3837 \end{cfa}
    3838 If ©precision© is 0, nothing is printed for zero.
    3839 If ©precision© is greater than the minimum, it becomes the minimum.
    3840 \begin{cfa}[belowskip=0pt]
    3841 sout | 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}
    3846 For floating-point types, ©precision© is the minimum number of digits after the decimal point.
    3847 \begin{cfa}[belowskip=0pt]
    3848 sout | 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]
    3851 27.®500®     27.®5®      28. 27.®50000000®
    3852 \end{cfa}
    3853 For 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]
    3855 sout | 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©}
    3863 For 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©).
    3864 If a value's significant digits is greater than ©significant©, the last significant digit is rounded up.
    3865 \begin{cfa}[belowskip=0pt]
    3866 sout | 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]
    3869 234.567 234.5®7®  234.®6®    23®5®
    3870 \end{cfa}
    3871 If 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]
    3873 sout | 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]
    3876 234567. 2.3457®e+05® 2.346®e+05® 2.35®e+05®
    3877 \end{cfa}
    3878 If ©significant© is greater than ©minimum©, it defines the number of printed characters.
    3879 \begin{cfa}[belowskip=0pt]
    3880 sout | 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]
    3883 234567. 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]
    3889 sout | 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]
    3892 27®  ® 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]
    3898 sout | pad0( wd( 4, 27 ) ) | pad0( wd( 4,3, 27 ) ) | pad0( wd( 8,3, 27.5 ) );
    3899 ®00®27  ®0®27 ®00®27.500
    39003334\end{cfa}
    39013335\end{enumerate}
     
    39073341int main( void ) {
    39083342        int x = 1, y = 2, z = 3;
    3909         sout | x | y | z;
     3343        sout | x | y | z | endl;
    39103344        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    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;
     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;
    39163350        sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
    3917                 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
     3351                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
    39183352        sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    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;
     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;
    39223356
    39233357        sepSet( sout, ", $" );                                          // set separator from " " to ", $"
    3924         sout | 1 | 2 | 3 | " \"" | sep | "\"";
     3358        sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl;
    39253359        sepSet( sout, " " );                                            // reset separator to " "
    3926         sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"";
     3360        sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
    39273361
    39283362        char store[sepSize];
    39293363        strcpy( store, sepGet( sout ) );
    39303364        sepSet( sout, "_" );
    3931         sout | 1 | 2 | 3;
     3365        sout | 1 | 2 | 3 | endl;
    39323366        sepSet( sout, store );
    3933         sout | 1 | 2 | 3;
     3367        sout | 1 | 2 | 3 | endl;
    39343368
    39353369        sepSetTuple( sout, " " );                                       // set tuple separator from ", " to " "
    3936         sout | t1 | t2 | " \"" | sepTuple | "\"";
     3370        sout | t1 | t2 | " \"" | sepTuple | "\"" | endl;
    39373371        sepSetTuple( sout, ", " );                                      // reset tuple separator to ", "
    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
     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
    39453379        sout | sepEnable;
    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
     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
    39503384}
    39513385
     
    39563390\end{comment}
    39573391%$
    3958 
    3959 
    3960 \subsection{Input Value Manipulators}
    3961 
    3962 The 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.
    3963 For ©_Bool© type, the constants are ©true© and ©false©.
    3964 For 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}
    3973 For 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.
    3974 Floating-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 
    3976 For 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.
    3977 Instead, the next sequence of non-whitespace characters are read, and the input sequence is terminated with delimiter ©'\0'©.
    3978 The string variable \emph{must} be large enough to contain the input sequence.
    3979 
    3980 The 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©
    3985 The argument defines a ©pattern© or ©length©.
    3986 The ©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.
    3987 The ©length© is composed of the next $N$ characters, including the newline character.
    3988 If the match successes, the input characters are discarded, and input continues with the next character.
    3989 If the match fails, the input characters are left unread.
    3990 \begin{cfa}[belowskip=0pt]
    3991 char sk[$\,$] = "abc";
    3992 sin | "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©}
    4002 For all types except ©char©, ©maximum© is the maximum number of characters read for the current operation.
    4003 \begin{cfa}[belowskip=0pt]
    4004 char s[10];   int i;   double d;   
    4005 sin | 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}
    4010 Note, input ©wdi© cannot be overloaded with output ©wd© because both have the same parameters but return different types.
    4011 Currently, \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©}
    4015 For 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]
    4017 double d;
    4018 sin | 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©}
    4026 For the C-string type, the argument defines a ©scanset© that matches any number of characters \emph{in} the set.
    4027 Matching characters are read into the C string and null terminated.
    4028 \begin{cfa}[belowskip=0pt]
    4029 char s[10];
    4030 sin | 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©}
    4038 For the C-string type, the argument defines a ©scanset© that matches any number of characters \emph{not in} the set.
    4039 Non-matching characters are read into the C string and null terminated.
    4040 \begin{cfa}[belowskip=0pt]
    4041 char s[10];
    4042 sin | excl( "abc", s );
    4043 \end{cfa}
    4044 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4045 ®xyz®bca
    4046 \end{cfa}
    4047 \end{enumerate}
    40483392
    40493393
     
    44153759\begin{itemize}
    44163760\item
    4417 not determining or writing long generic types,
    4418 \item
    4419 ensuring secondary variables, related to a primary variable, always have the same type.
     3761preventing having to determine or write long generic types,
     3762\item
     3763ensure secondary variables, related to a primary variable, always have the same type.
    44203764\end{itemize}
    44213765
     
    44393783There is also the conundrum in type inferencing of when to \emph{\Index{brand}} a type.
    44403784That is, when is the type of the variable more important than the type of its initialization expression.
    4441 For example, if a change is made in an initialization expression, it can cause cascading type changes and/or errors.
     3785For example, if a change is made in an initialization expression, it can cause significant cascading type changes and/or errors.
    44423786At some point, a variable type needs to remain constant and the expression to be in error when it changes.
    44433787
     
    46724016
    46734017coroutine Fibonacci {
    4674         int fn; §\C{// used for communication}§
     4018        int fn;                                                         §\C{// used for communication}§
    46754019};
    46764020void ?{}( Fibonacci * this ) {
     
    46784022}
    46794023void main( Fibonacci * this ) {
    4680         int fn1, fn2; §\C{// retained between resumes}§
    4681         this->fn = 0; §\C{// case 0}§
     4024        int fn1, fn2;                                           §\C{// retained between resumes}§
     4025        this->fn = 0;                                           §\C{// case 0}§
    46824026        fn1 = this->fn;
    4683         suspend(); §\C{// return to last resume}§
    4684 
    4685         this->fn = 1; §\C{// case 1}§
     4027        suspend();                                                      §\C{// return to last resume}§
     4028
     4029        this->fn = 1;                                           §\C{// case 1}§
    46864030        fn2 = fn1;
    46874031        fn1 = this->fn;
    4688         suspend(); §\C{// return to last resume}§
    4689 
    4690         for ( ;; ) { §\C{// general case}§
     4032        suspend();                                                      §\C{// return to last resume}§
     4033
     4034        for ( ;; ) {                                            §\C{// general case}§
    46914035                this->fn = fn1 + fn2;
    46924036                fn2 = fn1;
    46934037                fn1 = this->fn;
    4694                 suspend(); §\C{// return to last resume}§
     4038                suspend();                                              §\C{// return to last resume}§
    46954039        } // for
    46964040}
    46974041int next( Fibonacci * this ) {
    4698         resume( this ); §\C{// transfer to last suspend}§
     4042        resume( this );                                         §\C{// transfer to last suspend}§
    46994043        return this->fn;
    47004044}
     
    47024046        Fibonacci f1, f2;
    47034047        for ( int i = 1; i <= 10; i += 1 ) {
    4704                 sout | next( &f1 ) | ' ' | next( &f2 );
     4048                sout | next( &f1 ) | ' ' | next( &f2 ) | endl;
    47054049        } // for
    47064050}
     
    47684112                MyThread f[4];
    47694113        }
    4770         sout | global.value;
     4114        sout | global.value | endl;
    47714115}
    47724116\end{cfa}
     
    48464190void main( First * this ) {
    48474191        for ( int i = 0; i < 10; i += 1 ) {
    4848                 sout | "First : Suspend No." | i + 1;
     4192                sout | "First : Suspend No." | i + 1 | endl;
    48494193                yield();
    48504194        }
     
    48554199        wait( this->lock );
    48564200        for ( int i = 0; i < 10; i += 1 ) {
    4857                 sout | "Second : Suspend No." | i + 1;
     4201                sout | "Second : Suspend No." | i + 1 | endl;
    48584202                yield();
    48594203        }
     
    48624206int main( void ) {
    48634207        signal_once lock;
    4864         sout | "User main begin";
     4208        sout | "User main begin" | endl;
    48654209        {
    48664210                processor p;
     
    48704214                }
    48714215        }
    4872         sout | "User main end";
     4216        sout | "User main end" | endl;
    48734217}
    48744218\end{cfa}
     
    55674911void ?{}( Line * l ) {
    55684912        l->lnth = 0.0;
    5569         sout | "default";
     4913        sout | "default" | endl;
    55704914}
    55714915
     
    55744918void ?{}( Line * l, float lnth ) {
    55754919        l->lnth = lnth;
    5576         sout | "lnth" | l->lnth;
     4920        sout | "lnth" | l->lnth | endl;
    55774921
    55784922}
     
    55804924// destructor
    55814925void ^?() {
    5582         sout | "destroyed";
     4926        sout | "destroyed" | endl;
    55834927        l.lnth = 0.0;
    55844928}
     
    62415585In \CFA, there are ambiguous cases with dereference and operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be interpreted as:
    62425586\begin{cfa}
    6243 *?§\color{red}\textvisiblespace§*? §\C{// dereference operator, dereference operator}§
    6244 *§\color{red}\textvisiblespace§?*? §\C{// dereference, multiplication operator}§
     5587*?§\color{red}\textvisiblespace§*?              §\C{// dereference operator, dereference operator}§
     5588*§\color{red}\textvisiblespace§?*?              §\C{// dereference, multiplication operator}§
    62455589\end{cfa}
    62465590By default, the first interpretation is selected, which does not yield a meaningful parse.
     
    62945638\eg:
    62955639\begin{cfa}
    6296 x; §\C{// int x}§
    6297 *y; §\C{// int *y}§
    6298 f( p1, p2 ); §\C{// int f( int p1, int p2 );}§
    6299 g( p1, p2 ) int p1, p2; §\C{// int g( int p1, int p2 );}§
     5640x;                                                              §\C{// int x}§
     5641*y;                                                             §\C{// int *y}§
     5642f( p1, p2 );                                    §\C{// int f( int p1, int p2 );}§
     5643g( p1, p2 ) int p1, p2;                 §\C{// int g( int p1, int p2 );}§
    63005644\end{cfa}
    63015645\CFA continues to support K\&R routine definitions:
    63025646\begin{cfa}
    6303 f( a, b, c ) §\C{// default int return}§
    6304         int a, b; char c §\C{// K\&R parameter declarations}§
     5647f( a, b, c )                                    §\C{// default int return}§
     5648        int a, b; char c                        §\C{// K\&R parameter declarations}§
    63055649{
    63065650        ...
     
    63215665int rtn( int i );
    63225666int rtn( char c );
    6323 rtn( 'x' ); §\C{// programmer expects 2nd rtn to be called}§
     5667rtn( 'x' );                                             §\C{// programmer expects 2nd rtn to be called}§
    63245668\end{cfa}
    63255669\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
    63265670In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
    63275671\begin{cfa}
    6328 sout | 'x' | " " | (int)'x';
     5672sout | 'x' | " " | (int)'x' | endl;
    63295673x 120
    63305674\end{cfa}
     
    63435687\item[Change:] make string literals ©const©:
    63445688\begin{cfa}
    6345 char * p = "abc"; §\C{// valid in C, deprecated in \CFA}§
    6346 char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
     5689char * p = "abc";                               §\C{// valid in C, deprecated in \CFA}§
     5690char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
    63475691\end{cfa}
    63485692The type of a string literal is changed from ©[] char© to ©const [] char©.
     
    63515695\begin{cfa}
    63525696char * p = "abc";
    6353 p[0] = 'w'; §\C{// segment fault or change constant literal}§
     5697p[0] = 'w';                                             §\C{// segment fault or change constant literal}§
    63545698\end{cfa}
    63555699The same problem occurs when passing a string literal to a routine that changes its argument.
     
    63635707\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
    63645708\begin{cfa}
    6365 int i; §\C{// forward definition}§
    6366 int *j = ®&i®; §\C{// forward reference, valid in C, invalid in \CFA}§
    6367 int i = 0; §\C{// definition}§
     5709int i;                                                  §\C{// forward definition}§
     5710int *j = ®&i®;                                  §\C{// forward reference, valid in C, invalid in \CFA}§
     5711int i = 0;                                              §\C{// definition}§
    63685712\end{cfa}
    63695713is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
     
    63715715\begin{cfa}
    63725716struct X { int i; struct X *next; };
    6373 static struct X a; §\C{// forward definition}§
     5717static struct X a;                              §\C{// forward definition}§
    63745718static struct X b = { 0, ®&a® };§\C{// forward reference, valid in C, invalid in \CFA}§
    6375 static struct X a = { 1, &b }; §\C{// definition}§
     5719static struct X a = { 1, &b };  §\C{// definition}§
    63765720\end{cfa}
    63775721\item[Rationale:] avoids having different initialization rules for builtin types and user-defined types.
     
    63885732struct Person {
    63895733        enum ®Colour® { R, G, B };      §\C[7cm]{// nested type}§
    6390         struct Face { §\C{// nested type}§
    6391                 ®Colour® Eyes, Hair; §\C{// type defined outside (1 level)}§
     5734        struct Face {                           §\C{// nested type}§
     5735                ®Colour® Eyes, Hair;    §\C{// type defined outside (1 level)}§
    63925736        };
    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}§
     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}§
    63965740};
    6397 ®Colour® c = R; §\C{// type/enum defined same level}§
     5741®Colour® c = R;                                 §\C{// type/enum defined same level}§
    63985742Person®.Colour® pc = Person®.®R;§\C{// type/enum defined inside}§
    6399 Person®.®Face pretty; §\C{// type defined inside}\CRT§
     5743Person®.®Face pretty;                   §\C{// type defined inside}\CRT§
    64005744\end{cfa}
    64015745In 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.
     
    64145758\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:
    64155759\begin{cfa}
    6416 struct Y; §\C{// struct Y and struct X are at the same scope}§
     5760struct Y;                                               §\C{// struct Y and struct X are at the same scope}§
    64175761struct X {
    64185762        struct Y { /* ... */ } y;
     
    64295773\begin{cfa}
    64305774void foo() {
    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 *}§
     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 *}§
    64335777}
    64345778\end{cfa}
     
    66035947void * memalign( size_t align, size_t size );§\indexc{memalign}§
    66045948int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
     5949}
     5950
     5951// §\CFA§ safe equivalents, i.e., implicit size specification
     5952forall( dtype T | sized(T) ) T * malloc( void );
     5953forall( dtype T | sized(T) ) T * calloc( size_t dim );
     5954forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );
     5955forall( dtype T | sized(T) ) T * memalign( size_t align );
     5956forall( dtype T | sized(T) ) T * aligned_alloc( size_t align );
     5957forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align );
     5958
     5959// §\CFA§ safe general allocation, fill, resize, array
     5960forall( dtype T | sized(T) ) T * alloc( void );§\indexc{alloc}§
     5961forall( dtype T | sized(T) ) T * alloc( char fill );
     5962forall( dtype T | sized(T) ) T * alloc( size_t dim );
     5963forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill );
     5964forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim );
     5965forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
     5966
     5967// §\CFA§ safe general allocation, align, fill, array
     5968forall( dtype T | sized(T) ) T * align_alloc( size_t align );
     5969forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill );
     5970forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim );
     5971forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill );
    66055972
    66065973// C unsafe initialization/copy
     5974extern "C" {
    66075975void * memset( void * dest, int c, size_t size );
    66085976void * memcpy( void * dest, const void * src, size_t size );
    66095977}
    66105978
    6611 forall( 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 
    66345979// §\CFA§ safe initialization/copy, i.e., implicit size specification
    6635         T * memset( T * dest, char c );§\indexc{memset}§
    6636         T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
     5980forall( dtype T | sized(T) ) T * memset( T * dest, char c );§\indexc{memset}§
     5981forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
    66375982
    66385983// §\CFA§ safe initialization/copy array
    6639         T * amemset( T dest[], char c, size_t dim );
    6640         T * amemcpy( T dest[], const T src[], size_t dim );
    6641 }
     5984forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c );
     5985forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim );
    66425986
    66435987// §\CFA§ allocation/deallocation and constructor/destructor
     
    66555999
    66566000
    6657 \subsection{String to Value Conversion}
     6001\subsection{Conversion}
    66586002
    66596003\leavevmode
     
    66916035\leavevmode
    66926036\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6693 forall( otype T | { int ?<?( T, T ); } ) §\C{// location}§
     6037forall( otype T | { int ?<?( T, T ); } )        §\C{// location}§
    66946038T * bsearch( T key, const T * arr, size_t dim );§\indexc{bsearch}§
    66956039
    6696 forall( otype T | { int ?<?( T, T ); } ) §\C{// position}§
     6040forall( otype T | { int ?<?( T, T ); } )        §\C{// position}§
    66976041unsigned int bsearch( T key, const T * arr, size_t dim );
    66986042
    66996043forall( otype T | { int ?<?( T, T ); } )
    67006044void qsort( const T * arr, size_t dim );§\indexc{qsort}§
    6701 
    6702 forall( 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 
    6711 forall( 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 
    6720 forall( otype E | { int ?<?( E, E ); } ) {
    6721         void qsort( E * vals, size_t dim );§\indexc{qsort}§
    6722 }
    67236045\end{cfa}
    67246046
     
    67476069\leavevmode
    67486070\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6749 void srandom( unsigned int seed );§\indexc{srandom}§
    6750 char random( void );§\indexc{random}§
    6751 char random( char u ); §\C{// [0,u)}§
    6752 char random( char l, char u ); §\C{// [l,u)}§
    6753 int random( void );
    6754 int random( int u ); §\C{// [0,u)}§
    6755 int random( int l, int u ); §\C{// [l,u)}§
    6756 unsigned int random( void );
    6757 unsigned int random( unsigned int u ); §\C{// [0,u)}§
    6758 unsigned int random( unsigned int l, unsigned int u ); §\C{// [l,u)}§
    6759 long int random( void );
    6760 long int random( long int u ); §\C{// [0,u)}§
    6761 long int random( long int l, long int u ); §\C{// [l,u)}§
    6762 unsigned long int random( void );
    6763 unsigned long int random( unsigned long int u ); §\C{// [0,u)}§
    6764 unsigned long int random( unsigned long int l, unsigned long int u ); §\C{// [l,u)}§
    6765 float random( void );                                            §\C{// [0.0, 1.0)}§
    6766 double random( void );                                           §\C{// [0.0, 1.0)}§
    6767 float _Complex random( void );                           §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
    6768 double _Complex random( void );                          §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
    6769 long double _Complex random( void );             §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
     6071void rand48seed( long int s );§\indexc{rand48seed}§
     6072char rand48();§\indexc{rand48}§
     6073int rand48();
     6074unsigned int rand48();
     6075long int rand48();
     6076unsigned long int rand48();
     6077float rand48();
     6078double rand48();
     6079float _Complex rand48();
     6080double _Complex rand48();
     6081long double _Complex rand48();
    67706082\end{cfa}
    67716083
     
    68106122[ int, long double ] remquo( long double, long double );
    68116123
    6812 float div( float, float, int * );§\indexc{div}§ §\C{// alternative name for remquo}§
     6124float div( float, float, int * );§\indexc{div}§ §\C{// alternative name for remquo}§
    68136125double div( double, double, int * );
    68146126long double div( long double, long double, int * );
     
    69666278long double atan2( long double, long double );
    69676279
    6968 float atan( float, float ); §\C{// alternative name for atan2}§
     6280float atan( float, float );                                     §\C{// alternative name for atan2}§
    69696281double atan( double, double );§\indexc{atan}§
    69706282long double atan( long double, long double );
     
    71466458
    71476459
    7148 \section{Time Keeping}
    7149 \label{s:TimeKeeping}
     6460\section{Time}
     6461\label{s:TimeLib}
    71506462
    71516463
    71526464%\subsection{\texorpdfstring{\protect\lstinline@Duration@}{Duration}}
    7153 \subsection{\texorpdfstring{\LstBasicStyle{Duration}}{Duration}}
     6465\subsection{\texorpdfstring{\LstKeywordStyle{\textmd{Duration}}}{Duration}}
    71546466\label{s:Duration}
    71556467
     
    71576469\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    71586470struct Duration {
    7159         int64_t tv; §\C{// nanoseconds}§
     6471        int64_t tv;                                                     §\C{// nanoseconds}§
    71606472};
    71616473
     
    72006512
    72016513Duration abs( Duration rhs );
     6514
     6515forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur );
    72026516
    72036517Duration ?`ns( int64_t nsec );
     
    72236537int64_t ?`d( Duration dur );
    72246538int64_t ?`w( Duration dur );
    7225 
    7226 Duration max( Duration lhs, Duration rhs );
    7227 Duration min( Duration lhs, Duration rhs );
    72286539\end{cfa}
    72296540
    72306541
    72316542%\subsection{\texorpdfstring{\protect\lstinline@\timeval@}{timeval}}
    7232 \subsection{\texorpdfstring{\LstBasicStyle{timeval}}{timeval}}
     6543\subsection{\texorpdfstring{\LstKeywordStyle{\textmd{timeval}}}{timeval}}
    72336544\label{s:timeval}
    72346545
     
    72496560
    72506561
    7251 %\subsection{\texorpdfstring{\protect\lstinline@timespec@}{timespec}}
    7252 \subsection{\texorpdfstring{\LstBasicStyle{timespec}}{timespec}}
     6562\subsection{\texorpdfstring{\protect\lstinline@timespec@}{timespec}}
    72536563\label{s:timespec}
    72546564
     
    72696579
    72706580
    7271 %\subsection{\texorpdfstring{\protect\lstinline@itimerval@}{itimerval}}
    7272 \subsection{\texorpdfstring{\LstBasicStyle{itimerval}}{itimerval}}
     6581\subsection{\texorpdfstring{\protect\lstinline@itimerval@}{itimerval}}
    72736582\label{s:itimerval}
    72746583
     
    72806589
    72816590
    7282 %\subsection{\texorpdfstring{\protect\lstinline@Time@}{Time}}
    7283 \subsection{\texorpdfstring{\LstBasicStyle{Time}}{Time}}
     6591\subsection{\texorpdfstring{\protect\lstinline@Time@}{Time}}
    72846592\label{s:Time}
    72856593
     
    72876595\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    72886596struct Time {
    7289         uint64_t tv; §\C{// nanoseconds since UNIX epoch}§
     6597        uint64_t tv;                                            §\C{// nanoseconds since UNIX epoch}§
    72906598};
    72916599
    72926600void ?{}( Time & time );
    72936601void ?{}( Time & time, zero_t );
    7294 
     6602void ?{}( Time & time, int year, int month = 0, int day = 0, int hour = 0, int min = 0, int sec = 0, int nsec = 0 );
    72956603Time ?=?( Time & time, zero_t );
    72966604
     
    73016609Time ?=?( Time & time, timespec t );
    73026610
    7303 Time ?+?( Time & lhs, Duration rhs );
    7304 Time ?+?( Duration lhs, Time rhs );
    7305 Time ?+=?( Time & lhs, Duration rhs );
    7306 
    7307 Duration ?-?( Time lhs, Time rhs );
    7308 Time ?-?( Time lhs, Duration rhs );
    7309 Time ?-=?( 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 );
     6611Time ?+?( Time & lhs, Duration rhs ) { return (Time)@{ lhs.tv + rhs.tv }; }
     6612Time ?+?( Duration lhs, Time rhs ) { return rhs + lhs; }
     6613Time ?+=?( Time & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; }
     6614
     6615Duration ?-?( Time lhs, Time rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; }
     6616Time ?-?( Time lhs, Duration rhs ) { return (Time)@{ lhs.tv - rhs.tv }; }
     6617Time ?-=?( 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
     6625forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
    73166626
    73176627char * yy_mm_dd( Time time, char * buf );
     
    73316641
    73326642size_t strftime( char * buf, size_t size, const char * fmt, Time time );
    7333 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
    73346643\end{cfa}
    73356644
     
    73526661
    73536662%\subsection{\texorpdfstring{\protect\lstinline@Clock@}{Clock}}
    7354 \subsection{\texorpdfstring{\LstBasicStyle{Clock}}{Clock}}
     6663\subsection{\texorpdfstring{\LstKeywordStyle{\textmd{Clock}}}{Clock}}
    73556664\label{s:Clock}
    73566665
     
    73586667\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    73596668struct Clock {
    7360         Duration offset; §\C{// for virtual clock: contains offset from real-time}§
    7361         int clocktype; §\C{// implementation only -1 (virtual), CLOCK\_REALTIME}§
     6669        Duration offset;                                        §\C{// for virtual clock: contains offset from real-time}§
     6670        int clocktype;                                          §\C{// implementation only -1 (virtual), CLOCK\_REALTIME}§
    73626671};
    73636672
     
    73666675void ?{}( Clock & clk );
    73676676void ?{}( Clock & clk, Duration adj );
    7368 
    7369 Duration getResNsec(); §\C{// with nanoseconds}§
    7370 Duration getRes(); §\C{// without nanoseconds}§
    7371 
    7372 Time getTimeNsec(); §\C{// with nanoseconds}§
    7373 Time getTime(); §\C{// without nanoseconds}§
     6677Duration getRes();
     6678Time getTimeNsec();                                             §\C{// with nanoseconds}§
     6679Time getTime();                                                 §\C{// without nanoseconds}§
    73746680Time getTime( Clock & clk );
    73756681Time ?()( Clock & clk );
     
    73876693
    73886694\begin{cfa}
    7389 void ?{}( Int * this ); §\C{// constructor/destructor}§
     6695void ?{}( Int * this );                                 §\C{// constructor/destructor}§
    73906696void ?{}( Int * this, Int init );
    73916697void ?{}( Int * this, zero_t );
     
    73966702void ^?{}( Int * this );
    73976703
    7398 Int ?=?( Int * lhs, Int rhs ); §\C{// assignment}§
     6704Int ?=?( Int * lhs, Int rhs );                  §\C{// assignment}§
    73996705Int ?=?( Int * lhs, long int rhs );
    74006706Int ?=?( Int * lhs, unsigned long int rhs );
     
    74136719unsigned long int narrow( Int val );
    74146720
    7415 int ?==?( Int oper1, Int oper2 ); §\C{// comparison}§
     6721int ?==?( Int oper1, Int oper2 );               §\C{// comparison}§
    74166722int ?==?( Int oper1, long int oper2 );
    74176723int ?==?( long int oper2, Int oper1 );
     
    74496755int ?>=?( unsigned long int oper1, Int oper2 );
    74506756
    7451 Int +?( Int oper ); §\C{// arithmetic}§
     6757Int +?( Int oper );                                             §\C{// arithmetic}§
    74526758Int -?( Int oper );
    74536759Int ~?( Int oper );
     
    75316837Int ?>>=?( Int * lhs, mp_bitcnt_t shift );
    75326838
    7533 Int abs( Int oper ); §\C{// number functions}§
     6839Int abs( Int oper );                                    §\C{// number functions}§
    75346840Int fact( unsigned long int N );
    75356841Int gcd( Int oper1, Int oper2 );
     
    75566862#include <gmp>§\indexc{gmp}§
    75576863int main( void ) {
    7558         sout | "Factorial Numbers";
     6864        sout | "Factorial Numbers" | endl;
    75596865        Int fact = 1;
    75606866
    7561         sout | 0 | fact;
     6867        sout | 0 | fact | endl;
    75626868        for ( unsigned int i = 1; i <= 40; i += 1 ) {
    75636869                fact *= i;
    7564                 sout | i | fact;
     6870                sout | i | fact | endl;
    75656871        }
    75666872}
     
    76426948// implementation
    76436949struct Rational {§\indexc{Rational}§
    7644         long int numerator, denominator; §\C{// invariant: denominator > 0}§
     6950        long int numerator, denominator;        §\C{// invariant: denominator > 0}§
    76456951}; // Rational
    76466952
    7647 Rational rational(); §\C{// constructors}§
     6953Rational rational();                                    §\C{// constructors}§
    76486954Rational rational( long int n );
    76496955Rational rational( long int n, long int d );
     
    76516957void ?{}( Rational * r, one_t );
    76526958
    7653 long int numerator( Rational r ); §\C{// numerator/denominator getter/setter}§
     6959long int numerator( Rational r );               §\C{// numerator/denominator getter/setter}§
    76546960long int numerator( Rational r, long int n );
    76556961long int denominator( Rational r );
    76566962long int denominator( Rational r, long int d );
    76576963
    7658 int ?==?( Rational l, Rational r ); §\C{// comparison}§
     6964int ?==?( Rational l, Rational r );             §\C{// comparison}§
    76596965int ?!=?( Rational l, Rational r );
    76606966int ?<?( Rational l, Rational r );
     
    76636969int ?>=?( Rational l, Rational r );
    76646970
    7665 Rational -?( Rational r ); §\C{// arithmetic}§
     6971Rational -?( Rational r );                              §\C{// arithmetic}§
    76666972Rational ?+?( Rational l, Rational r );
    76676973Rational ?-?( Rational l, Rational r );
     
    76696975Rational ?/?( Rational l, Rational r );
    76706976
    7671 double widen( Rational r ); §\C{// conversion}§
     6977double widen( Rational r );                             §\C{// conversion}§
    76726978Rational narrow( double f, long int md );
    76736979
Note: See TracChangeset for help on using the changeset viewer.