Changeset b1e63ac5 for doc


Ignore:
Timestamp:
Jul 4, 2017, 9:40:16 AM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, stuck-waitfor-destruct, with_gc
Children:
208e5be
Parents:
9c951e3 (diff), f7cb0bc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into references

Location:
doc
Files:
18 added
6 deleted
14 edited
12 moved

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.tex

    r9c951e3 rb1e63ac5  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon May 15 18:03:29 2017
    14 %% Update Count     : 302
     13%% Last Modified On : Sun Jun 18 20:32:32 2017
     14%% Update Count     : 319
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    3636% Names used in the document.
    3737
    38 \newcommand{\CFA}{\textrm{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name
     38\newcommand{\CFAIcon}{\textrm{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name
     39\newcommand{\CFA}{\protect\CFAIcon} % safe for section/caption
    3940\newcommand{\CFL}{\textrm{Cforall}\xspace} % Cforall symbolic name
    4041\newcommand{\Celeven}{\textrm{C11}\xspace} % C11 symbolic name
     
    241242belowskip=3pt,
    242243% replace/adjust listing characters that look bad in sanserif
    243 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
     244literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
    244245        {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
    245         {__}{\_\,\_}2 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2
    246         {___}{\_\,\_\,\_}3,
     246        {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2,
    247247moredelim=**[is][\color{red}]{®}{®},                                    % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
    248248moredelim=**[is][\color{blue}]{ß}{ß},                                   % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
  • doc/LaTeXmacros/lstlang.sty

    r9c951e3 rb1e63ac5  
    88%% Created On       : Sat May 13 16:34:42 2017
    99%% Last Modified By : Peter A. Buhr
    10 %% Last Modified On : Sat May 13 16:49:09 2017
    11 %% Update Count     : 4
     10%% Last Modified On : Fri May 26 12:47:09 2017
     11%% Update Count     : 8
    1212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1313
     
    107107\lstdefinelanguage{CFA}[ANSI]{C}{
    108108        morekeywords={
    109                 _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, _At, _Atomic, __attribute,
     109                _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, _At, __attribute,
    110110                __attribute__, auto, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__,
    111                 __const, __const__, coroutine, disable, dtype, enable, __extension__, fallthrough, fallthru,
    112                 finally, forall, ftype, _Generic, _Imaginary, inline, __label__, lvalue, monitor, mutex,
    113                 _Noreturn, one_t, otype, restrict, _Static_assert, thread, _Thread_local, throw, throwResume,
    114                 trait, try, ttype, typeof, __typeof, __typeof__, zero_t},
     111                __const, __const__, disable, dtype, enable, __extension__, fallthrough, fallthru,
     112                finally, forall, ftype, _Generic, _Imaginary, inline, __label__, lvalue, _Noreturn, one_t,
     113                otype, restrict, _Static_assert, throw, throwResume, trait, try, ttype, typeof, __typeof,
     114                __typeof__, zero_t},
     115        morekeywords=[2]{
     116                _Atomic, coroutine, is_coroutine, is_monitor, is_thread, monitor, mutex, nomutex,
     117                resume, suspend, thread, _Thread_local, yield},
     118}
     119
     120% uC++ programming language, based on ANSI C++
     121\lstdefinelanguage{uC++}[ANSI]{C++}{
     122        morekeywords={
     123                _Accept, _AcceptReturn, _AcceptWait, _Actor, _At, _CatchResume, _Cormonitor, _Coroutine, _Disable,
     124                _Else, _Enable, _Event, _Finally, _Monitor, _Mutex, _Nomutex, _PeriodicTask, _RealTimeTask,
     125                _Resume, _Select, _SporadicTask, _Task, _Timeout, _When, _With, _Throw},
    115126}
    116127
  • doc/bibliography/cfa.bib

    r9c951e3 rb1e63ac5  
    862862}
    863863
    864 @techreport{C11,
    865     type        = {International Standard},
     864@manual{C11,
    866865    keywords    = {ISO/IEC C 11},
    867866    contributer = {pabuhr@plg},
    868     key         = {{ISO/IEC} 9889-2011},
    869     title       = {American National Standard Information technology -- Programming Languages -- {C}},
    870     institution = {International Standard Organization},
    871     address     = {http://www.iso.org},
     867    author      = {C11},
     868    title       = {Programming Languages -- {C} {ISO/IEC} 9889:2011},
     869    edition     = {3rd},
     870    publisher   = {International Standard Organization},
     871    address     = {\href{https://www.iso.org/standard/57853.html}{https://\-www.iso.org/\-standard/\-57853.html}},
    872872    year        = 2012,
    873873}
     
    877877    keywords    = {ISO/IEC TS 19217:2015},
    878878    contributer = {a3moss@uwaterloo.ca},
    879     key         = {{ISO/IEC} {TS} 19217},
    880879    author      = {Concepts},
    881     title       = {Information technology -- Programming languages -- {C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}} Extensions for concepts},
    882     institution = {International Standard Organization},
    883     address     = {http://www.iso.org},
     880    title       = {Information technology -- Programming languages -- {C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}} Extensions for concepts {ISO/IEC} {TS} 19217:2015},
     881    publisher   = {International Standard Organization},
     882    address     = {\href{https://www.iso.org/standard/64031.html}{https://\-www.iso.org/\-standard/\-64031.html}},
    884883    year        = 2015
    885884}
     
    10961095    keywords    = {ISO/IEC Cobol 14},
    10971096    contributer = {pabuhr@plg},
    1098     key         = {Cobol14},
    1099     title       = {Programming Languages -- {Cobol}},
     1097    author      = {Cobol14},
     1098    title       = {Programming Languages -- {Cobol} ISO/IEC 1989:2014},
    11001099    edition     = {2nd},
    1101     organization= {International Standard ISO/IEC 1989:2014},
    1102     publisher   = {International Standard Organization},
    1103     address     = {http://www.iso.org},
     1100    institution = {International Standard Organization},
     1101    address     = {\href{https://www.iso.org/standard/51416.html}{https://\-www.iso.org/\-standard/\-51416.html}},
    11041102    year        = 2014,
    11051103}
     
    28362834    keywords    = {ISO/IEC Fortran 08},
    28372835    contributer = {pabuhr@plg},
    2838     key         = {Fortran08},
    2839     title       = {Programming Languages -- {Fortran} Part 1},
    2840     organization= {International Standard ISO/IEC 1989:2014},
     2836    author      = {Fortran08},
     2837    title       = {Programming Languages -- {Fortran} Part 1:Base Language ISO/IEC 1539-1:2010},
     2838    edition     = {3rd},
    28412839    publisher   = {International Standard Organization},
    2842     address     = {http://www.iso.org},
     2840    address     = {\href{https://www.iso.org/standard/50459.html}{https://\-www.iso.org/\-standard/\-50459.html}},
    28432841    year        = 2010,
    28442842}
     
    30373035    year        = 1992,
    30383036    pages       = {T1-53},
     3037}
     3038
     3039@manual{GMP,
     3040    keywords    = {GMP arbitrary-precision library},
     3041    contributer = {pabuhr@plg},
     3042    title       = {{GNU} Multiple Precision Arithmetic Library},
     3043    author      = {GMP},
     3044    organization= {GNU},
     3045    year        = 2016,
     3046    note        = {\href{https://gmplib.org}{https://\-gmplib.org}},
    30393047}
    30403048
     
    44164424    keywords    = {Plan 9},
    44174425    contributer = {pabuhr@plg},
    4418     title       = {A New C Compiler},
     4426    title       = {A New {C} Compiler},
    44194427    author      = {Ken Thompson},
    44204428    booktitle   = {Proceedings of the Summer 1990 UKUUG Conference},
    44214429    year        = 1990,
    44224430    pages       = {41--51},
    4423     url         = {http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compiler.pdf}
     4431    note        = {\href{http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compiler.pdf}{http://\-doc.cat-v.org/\-bell\_labs/\-new\_c\_compilers/\-new\_c\_compiler.pdf}},
    44244432}
    44254433
     
    53595367}
    53605368
    5361 @manual{ANSI14:C++,
     5369@manual{C++14,
    53625370    keywords    = {ISO/IEC C++ 14},
    53635371    contributer = {pabuhr@plg},
    5364     key         = {C++14},
    5365     title       = {Programming Languages -- {C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}}},
     5372    author      = {C++14},
     5373    title       = {Programming Languages -- {C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}} ISO/IEC 14882:2014},
    53665374    edition     = {4th},
    5367     organization= {International Standard ISO/IEC 14882:2014 (E)},
    53685375    publisher   = {International Standard Organization},
    5369     address     = {http://www.iso.org},
     5376    address     = {\href{https://www.iso.org/standard/64029.html}{https://\-www.iso.org/\-standard/\-64029.html}},
    53705377    year        = 2014,
    53715378}
     
    57065713
    57075714@manual{Ada12,
    5708     keywords    = {Ada},
    5709     contributer = {pabuhr@plg},
    5710     title       = {Programming languages -- {Ada}},
     5715    keywords    = {ISO/IEC Ada},
     5716    contributer = {pabuhr@plg},
     5717    author      = {Ada12},
     5718    title       = {Programming languages -- {Ada} ISO/IEC 8652:2012},
    57115719    edition     = {3rd},
    5712     organization= {International Standard ISO/IEC 1989:2014},
    57135720    publisher   = {International Standard Organization},
    5714     address     = {http://www.iso.org},
     5721    address     = {\href{https://www.iso.org/standard/61507.html}{https://\-www.iso.org/\-standard/\-61507.html}},
    57155722    year        = 2012,
    57165723}
  • doc/proposals/concurrency/.gitignore

    r9c951e3 rb1e63ac5  
    1 concurrency.aux
    2 concurrency.acn
    3 concurrency.acr
    4 concurrency.alg
    5 concurrency.bbl
    6 concurrency.blg
    7 concurrency.brf
    8 concurrency.dvi
    9 concurrency.glg
    10 concurrency.glo
    11 concurrency.gls
    12 concurrency.idx
    13 concurrency.ind
    14 concurrency.ist
    15 concurrency.log
    16 concurrency.out
    17 concurrency.pdf
    18 concurrency.ps
    19 version.aux
    20 monitor.tex
    21 ext_monitor.tex
     1build/*.aux
     2build/*.acn
     3build/*.acr
     4build/*.alg
     5build/*.bbl
     6build/*.blg
     7build/*.brf
     8build/*.dvi
     9build/*.glg
     10build/*.glo
     11build/*.gls
     12build/*.idx
     13build/*.ind
     14build/*.ist
     15build/*.log
     16build/*.out
     17build/*.ps
     18build/*.tex
     19build/*.toc
     20*.pdf
     21
     22examples
  • doc/proposals/concurrency/Makefile

    r9c951e3 rb1e63ac5  
    11## Define the appropriate configuration variables.
    22
    3 TeXLIB = .:../../LaTeXmacros:../../LaTeXmacros/listings:../../LaTeXmacros/enumitem:~/bibliographies:
    4 LaTeX  = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex -halt-on-error
    5 BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex
     3TeXLIB = .:./style:./text:./annex:./build:../../LaTeXmacros:../../LaTeXmacros/listings:../../LaTeXmacros/enumitem:~/bibliographies:
     4LaTeX  = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex -halt-on-error -output-directory=build -interaction=nonstopmode
     5BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex -terse
    66
    77## Define the text source files.
    88
    99SOURCES = ${addsuffix .tex, \
    10 concurrency \
    11 style \
    12 cfa-format \
    13 glossary \
     10thesis \
     11style/style \
     12style/cfa-format \
     13annex/glossary \
     14text/intro \
     15text/cforall \
     16text/basics \
     17text/concurrency \
     18text/parallelism \
    1419}
    1520
    16 FIGURES = ${addsuffix .tex, \
     21FIGURES = ${addprefix build/, ${addsuffix .tex, \
    1722        monitor \
    1823        ext_monitor \
    19 }
     24}}
    2025
    2126PICTURES = ${addsuffix .pstex, \
     
    3035## Define the documents that need to be made.
    3136
    32 DOCUMENT = concurrency.pdf
     37DOCUMENT = thesis.pdf
    3338
    3439# Directives #
     
    3742
    3843clean :
    39         rm -f *.bbl *.aux *.dvi *.idx *.ilg *.ind *.brf *.out *.log *.toc *.blg *.pstex_t *.cf *.glg *.glo *.gls *.ist *.acn *.acr *.alg \
    40                 ${FIGURES} ${PICTURES} ${PROGRAMS} ${GRAPHS} ${basename ${DOCUMENT}}.ps ${DOCUMENT}
     44        @rm -fv ${DOCUMENT} \
     45        build/*.acn     \
     46        build/*.acr     \
     47        build/*.alg     \
     48        build/*.aux     \
     49        build/*.bbl     \
     50        build/*.blg     \
     51        build/*.brf     \
     52        build/*.cf      \
     53        build/*.dvi     \
     54        build/*.glg     \
     55        build/*.glo     \
     56        build/*.gls     \
     57        build/*.ist     \
     58        build/*.idx     \
     59        build/*.ilg     \
     60        build/*.ind     \
     61        build/*.log     \
     62        build/*.out     \
     63        build/*.ps      \
     64        build/*.pstex_t \
     65        build/*.tex     \
     66        build/*.toc     \
     67
    4168
    4269# File Dependencies #
    4370
    44 ${DOCUMENT} : ${basename ${DOCUMENT}}.ps
     71${DOCUMENT} : build/${basename ${DOCUMENT}}.ps
    4572        ps2pdf $<
    4673
    47 ${basename ${DOCUMENT}}.ps : ${basename ${DOCUMENT}}.dvi
     74build/${basename ${DOCUMENT}}.ps : build/${basename ${DOCUMENT}}.dvi
    4875        dvips $< -o $@
    4976
    50 ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \
    51                 ../../LaTeXmacros/common.tex ../../LaTeXmacros/indexstyle
    52         # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
    53         if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi
    54         # Must have *.aux file containing citations for bibtex
    55         if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi
    56         -${BibTeX} ${basename $@}
    57         # Some citations reference others so run steps again to resolve these citations
    58         ${LaTeX} ${basename $@}.tex
    59         -${BibTeX} ${basename $@}
    60         # Make index from *.aux entries and input index at end of document
    61         makeglossaries ${basename $@}
    62         #${LaTeX} ${basename $@}.tex
    63         # Run again to get index title into table of contents
    64         ${LaTeX} ${basename $@}.tex
    65         -./bump_ver.sh
    66         ${LaTeX} ${basename $@}.tex
     77build/${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex ../../LaTeXmacros/common.tex ../../LaTeXmacros/indexstyle
     78
     79        @ if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi                           # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
     80        @ echo "Citation lookup"                                                                                        # Must have *.aux file containing citations for bibtex
     81        @ if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename ${notdir $@}}.tex ; fi
     82        @ echo "Citation Pass 1"
     83        @ -${BibTeX} ${basename $@}                                                                                     # Some citations reference others so run steps again to resolve these citations
     84        @ echo "Citation Pass 2"
     85        @ ${LaTeX} ${basename ${notdir $@}}.tex
     86        @ -${BibTeX} ${basename $@}
     87        @ echo "Glossary"
     88        makeglossaries -q -s ${basename $@}.ist ${basename $@}                                          # Make index from *.aux entries and input index at end of document
     89        @ echo ".dvi generation"
     90        @ -build/bump_ver.sh
     91        @ ${LaTeX} ${basename ${notdir $@}}.tex                                                                 # Run again to get index title into table of contents
    6792
    6893
     
    7297## Define the default recipes.
    7398
    74 %.tex : %.fig
     99build/%.tex : figures/%.fig
    75100        fig2dev -L eepic $< > $@
    76101
    77 %.ps : %.fig
     102build/%.ps : figures/%.fig
    78103        fig2dev -L ps $< > $@
    79104
    80 %.pstex : %.fig
     105build/%.pstex : figures/%.fig
    81106        fig2dev -L pstex $< > $@
    82107        fig2dev -L pstex_t -p $@ $< > $@_t
  • doc/proposals/concurrency/style/cfa-format.tex

    r9c951e3 rb1e63ac5  
    1 \usepackage{xcolor}
     1\usepackage[usenames,dvipsnames]{xcolor}
    22\usepackage{listings}
    33\usepackage{inconsolata}
     
    144144  % moredelim=** allows cumulative application
    145145}
    146 \lstset{
    147   morekeywords=[2]{nomutex,mutex,thread,wait,wait_release,signal,signal_block,accept,monitor,suspend,resume,coroutine}
    148   language = CFA,
    149   style=defaultStyle
    150 }
     146
     147\lstdefinestyle{cfaStyle}{
     148  escapeinside={@@},
     149  basicstyle=\linespread{0.9}\tt\footnotesize,          % reduce line spacing and use typewriter font
     150  keywordstyle=\bfseries\color{blue},
     151  keywordstyle=[2]\bfseries\color{Plum},
     152  commentstyle=\itshape\color{OliveGreen},                  % green and italic comments
     153  identifierstyle=\color{identifierCol},
     154  stringstyle=\sf\color{Mahogany},                                % use sanserif font
     155  mathescape=true,
     156  columns=fixed,
     157  aboveskip=4pt,                                  % spacing above/below code block
     158  belowskip=3pt,
     159  keepspaces=true,
     160  % frame=lines,
     161  literate=,
     162  showlines=true,                                 % show blank lines at end of code
     163  showspaces=false,
     164  showstringspaces=false,
     165  escapechar=\$,
     166  xleftmargin=\parindentlnth,                     % indent code to paragraph indentation
     167  moredelim=[is][\color{red}\bfseries]{**R**}{**R**},    % red highlighting
     168  morekeywords=[2]{accept, signal, signal_block, wait},
     169}
     170
    151171\lstMakeShortInline[basewidth=0.5em,breaklines=true,basicstyle=\normalsize\ttfamily\color{basicCol}]@  % single-character for \lstinline
    152172
    153 \lstnewenvironment{cfacode}[1][]{ %
    154   \lstset{ %
    155     language = CFA, %
    156     style=defaultStyle, %
    157     morekeywords=[2]{nomutex,mutex,thread,wait,signal,signal_block,accept,monitor,suspend,resume,coroutine}, %
    158     #1 %
    159   } %
     173\lstnewenvironment{ccode}[1][]{
     174  \lstset{
     175    language = C,
     176    style=defaultStyle,
     177    #1
     178  }
     179}{}
     180
     181\lstnewenvironment{cfacode}[1][]{
     182  \lstset{
     183    language = CFA,
     184    style=cfaStyle,
     185    #1
     186  }
    160187}{}
    161188
     
    169196
    170197\lstnewenvironment{cppcode}[1][]{
     198  \lstset{
     199    language = c++,
     200    style=defaultStyle,
     201    #1
     202  }
     203}{}
     204
     205\lstnewenvironment{ucppcode}[1][]{
    171206  \lstset{
    172207    language = c++,
     
    219254\newcommand{\one}{\lstinline{one_t}\xspace}
    220255\newcommand{\ateq}{\lstinline{\@=}\xspace}
     256\newcommand{\code}[1]{\lstinline[language=CFA,style=cfaStyle]{#1}}
     257\newcommand{\pscode}[1]{\lstinline[language=pseudo,style=pseudoStyle]{#1}}
  • doc/proposals/concurrency/version

    r9c951e3 rb1e63ac5  
    1 0.8.2
     10.9.119
  • doc/refrat/Makefile

    r9c951e3 rb1e63ac5  
    4444
    4545${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \
    46                 ../LaTeXmacros/common.tex ../LaTeXmacros/indexstyle ../bibliography/cfa.bib
     46                ../LaTeXmacros/common.tex ../LaTeXmacros/lstlang.sty ../LaTeXmacros/indexstyle ../bibliography/cfa.bib
    4747        # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
    4848        if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi
     
    7070        fig2dev -L ps $< > $@
    7171
     72%.pstex : %.fig
     73        fig2dev -L pstex $< > $@
     74        fig2dev -L pstex_t -p $@ $< > $@_t
     75
    7276# Local Variables: #
    7377# compile-command: "make" #
  • doc/refrat/refrat.bib

    r9c951e3 rb1e63ac5  
    22
    33@manual{ANS:C,
    4     keywords = {ANSI C},
    5     contributer = {gjditchfield@msg},
    6     title = {American National Standard for Information Systems --
     4    keywords    = {ANSI C},
     5    contributer = {gjditchfield@msg},
     6    title       = {American National Standard for Information Systems --
    77          Programming Language -- {C}},
    8     organization = {American National Standards Institute},
    9     address = {1430 Broadway, New York, New York  10018},
    10     month = dec, year = 1989,
    11     note = {X3.159-1989}
     8    organization= {American National Standards Institute},
     9    address     = {1430 Broadway, New York, New York  10018},
     10    month       = dec, year     = 1989,
     11    note        = {X3.159-1989}
    1212}
    1313
    1414@manual{ANS:C11,
    15     keywords = {ANS:C11},
    16     contributer = {gjditchfield@acm.org},
    17     title = {American National Standard Information Systems --
     15    keywords    = {ANS:C11},
     16    contributer = {gjditchfield@acm.org},
     17    title       = {American National Standard Information Systems --
    1818          Programming languages -- {C}},
    19     organization = {American National Standards Institute},
    20     address = {25 West 43rd Street, New York, New York 10036},
    21     month = may, year = 2012,
    22     note = {INCITS/ISO/IEC 9899-2011[2012]}
     19    organization= {American National Standards Institute},
     20    address     = {25 West 43rd Street, New York, New York 10036},
     21    month       = may, year     = 2012,
     22    note        = {INCITS/ISO/IEC 9899-2011[2012]}
    2323}
    2424
    2525@book{c++,
    26     keywords = {C++, ANSI},
    27     author = {Margaret A. Ellis and Bjarne Stroustrup},
    28     title = {The Annotated {C}{\tt ++} Reference Manual},
    29     publisher = {Addison Wesley},
    30     year = 1990,
    31     edition = {first}
     26    keywords    = {C++, ANSI},
     27    author      = {Margaret A. Ellis and Bjarne Stroustrup},
     28    title       = {The Annotated {C}{\tt ++} Reference Manual},
     29    publisher   = {Addison Wesley},
     30    year        = 1990,
     31    edition     = {first}
    3232}
    3333
    3434@Unpublished{Ditchfield96:Overview,
    35   author =      "Glen Ditchfield",
    36   title =        "An Overview of Cforall",
    37   note =        "in preparation",
    38   year =        1996
     35    author      = "Glen Ditchfield",
     36    title       = "An Overview of Cforall",
     37    note        = "in preparation",
     38    year        = 1996
    3939}
    4040
    4141@article{Bak:overload,
    42     keywords = {compilation},
    43     contributer = {gjditchfield@msg},
    44     author = {T. P. Baker},
    45     title = {A One-Pass Algorithm for Overload Resolution in {Ada}},
    46     journal = toplas,
    47     year = 1982,
    48     month = oct, volume = 4, number = 4, pages = {601--614},
    49     abstract = {
     42    keywords    = {compilation},
     43    contributer = {gjditchfield@msg},
     44    author      = {T. P. Baker},
     45    title       = {A One-Pass Algorithm for Overload Resolution in {Ada}},
     46    journal     = toplas,
     47    year        = 1982,
     48    month       = oct, volume   = 4, number     = 4, pages      = {601--614},
     49    abstract    = {
    5050        A simple method is presented for detecting ambiguities and finding
    5151        the correct interpretations of expressions in the programming
     
    5656        approach is demonstrated by a brief formal argument.
    5757    },
    58     comment = {
     58    comment     = {
    5959        See also \cite{D:overload}.
    6060        }
     
    7777
    7878@book{clu,
    79     keywords = {CLU},
    80     contributer = {gjditchfield@msg},
    81     author = {Barbara Liskov and Russell Atkinson and Toby Bloom and Eliot
     79    keywords    = {CLU},
     80    contributer = {gjditchfield@msg},
     81    author      = {Barbara Liskov and Russell Atkinson and Toby Bloom and Eliot
    8282    Moss and J. Craig Schaffert and Robert Scheifler and Alan Snyder},
    83     title = {CLU Reference Manual},
    84     publisher = {Springer-Verlag},
    85     year = 1981,
    86     volume = 114,
    87     series = {Lecture Notes in Computer Science}
     83    title       = {CLU Reference Manual},
     84    publisher   = {Springer-Verlag},
     85    year        = 1981,
     86    volume      = 114,
     87    series      = {Lecture Notes in Computer Science}
    8888}
    8989
    9090@manual{SIMULA87,
    91     keywords = {Simula standard},
    92     contributer = {gjditchfield@msg},
    93     title = {Databehandling -- Programspr{\aa}k -- {SIMULA}},
    94     organization = {Standardiseringskommissionen i Sverige},
    95     note = {Svensk Standard SS 63 61 14},
    96     year = 1987,
    97     abstract = {
     91    keywords    = {Simula standard},
     92    contributer = {gjditchfield@msg},
     93    title       = {Databehandling -- Programspr{\aa}k -- {SIMULA}},
     94    organization        = {Standardiseringskommissionen i Sverige},
     95    note        = {Svensk Standard SS 63 61 14},
     96    year        = 1987,
     97    abstract    = {
    9898        Standard for the programming language SIMULA.  Written in English.
    9999    }
     
    112112
    113113@inproceedings{Thompson90new,
    114   title = {A New C Compiler},
    115   author = {Ken Thompson},
    116   booktitle = {Proceedings of the Summer 1990 UKUUG Conference},
    117   year = 1990,
    118   pages = {41--51}
     114    title       = {A New {C} Compiler},
     115    author      = {Ken Thompson},
     116    booktitle   = {Proceedings of the Summer 1990 UKUUG Conference},
     117    year        = 1990,
     118    pages       = {41--51}
    119119}
  • doc/refrat/refrat.tex

    r9c951e3 rb1e63ac5  
    1111%% Created On       : Wed Apr  6 14:52:25 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Wed Apr  5 23:23:28 2017
    14 %% Update Count     : 79
     13%% Last Modified On : Fri Jun  2 10:43:14 2017
     14%% Update Count     : 83
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    2929\usepackage{epic,eepic}
    3030\usepackage{upquote}                                                                    % switch curled `'" to straight
     31\usepackage{calc}
    3132\usepackage{xspace}
    3233\usepackage{varioref}                                                                   % extended references
     
    6263% Names used in the document.
    6364\newcommand{\Version}{\input{../../version}}
    64 
    6565\newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}}
    6666\newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
     
    9797\renewcommand{\chaptermark}[1]{\markboth{\thechapter\quad #1}{\thechapter\quad #1}}
    9898\renewcommand{\sectionmark}[1]{\markboth{\thesection\quad #1}{\thesection\quad #1}}
     99\renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}}
    99100\pagenumbering{roman}
    100101\linenumbers                                            % comment out to turn off line numbering
     
    121122
    122123This document is a reference manual and rationale for \CFA, a polymorphic extension of the C programming language.
    123 It makes frequent reference to the {\c11} standard \cite{C11}, and occasionally compares \CFA to {\CC} \cite{C++}.
    124 
    125 The manual deliberately imitates the ordering of the {\c11} standard (although the section numbering differs).
    126 Unfortunately, this means the manual contains more ``forward references'' than usual, making it harder to follow if the reader does not have a copy of the {\c11} standard.
     124It covers low-level syntactic and semantic details of the language to address complex language issues for programmers, and provide language implementers with a precise language description.
     125It makes frequent reference to the \Celeven standard~\cite{C11}, and occasionally compares \CFA to \CC~\cite{C++}.
     126Changes to the syntax and additional features are expected to be included in later revisions.
     127
     128The manual deliberately imitates the ordering of the \Celeven standard (although the section numbering differs).
     129Unfortunately, this means the manual contains more ``forward references'' than usual, making it harder to follow if the reader does not have a copy of the \Celeven standard.
    127130For a simple introduction to \CFA, see the companion document ``An Overview of \CFA''
    128131\cite{Ditchfield96:Overview}.
     
    139142\chapter{Terms, definitions, and symbols}
    140143
    141 Terms from the {\c11} standard used in this document have the same meaning as in the {\c11} standard.
     144Terms from the \Celeven standard used in this document have the same meaning as in the \Celeven standard.
    142145
    143146% No ``Conformance'' or ``Environment'' chapters yet.
     
    149152
    150153\section{Notation}
    151 The syntax notation used in this document is the same as in the {\c11} standard, with one exception: ellipsis in the definition of a nonterminal, as in ``\emph{declaration:} \ldots'', indicates that these rules extend a previous definition, which occurs in this document or in the {\c11} standard.
     154The syntax notation used in this document is the same as in the \Celeven standard, with one exception: ellipsis in the definition of a nonterminal, as in ``\emph{declaration:} \ldots'', indicates that these rules extend a previous definition, which occurs in this document or in the \Celeven standard.
    152155
    153156
     
    162165\begin{rationale}
    163166Hence, a \CFA program can declare an ©int v© and a ©float v© in the same scope;
    164 a {\CC} program can not.
     167a \CC program can not.
    165168\end{rationale}
    166169
     
    285288
    286289\begin{rationale}
    287 Note that {\c11} does not include conversion from \Index{real type}s to \Index{complex type}s in the usual arithmetic conversions, and \CFA does not include them as safe conversions.
     290Note that \Celeven does not include conversion from \Index{real type}s to \Index{complex type}s in the usual arithmetic conversions, and \CFA does not include them as safe conversions.
    288291\end{rationale}
    289292
     
    370373\begin{rationale}
    371374As in C, there is an implicit conversion from ©void *© to any pointer type.
    372 This is clearly dangerous, and {\CC} does not have this implicit conversion.
     375This is clearly dangerous, and \CC does not have this implicit conversion.
    373376\CFA\index{deficiencies!void * conversion} keeps it, in the interest of remaining as pure a superset of C as possible, but discourages it by making it unsafe.
    374377\end{rationale}
     
    608611
    609612There are two notable differences between \CFA's overload resolution rules and the rules for
    610 {\CC} defined in \cite{C++}.
     613\CC defined in \cite{C++}.
    611614First, the result type of a function plays a role.
    612 In {\CC}, a function call must be completely resolved based on the arguments to the call in most circumstances.
     615In \CC, a function call must be completely resolved based on the arguments to the call in most circumstances.
    613616In \CFA, a function call may have several interpretations, each with a different result type, and the interpretations of the containing context choose among them.
    614617Second, safe conversions are used to choose among interpretations of all sorts of functions;
    615 in {\CC}, the ``usual arithmetic conversions'' are a separate set of rules that apply only to the built-in operators.
     618in \CC, the ``usual arithmetic conversions'' are a separate set of rules that apply only to the built-in operators.
    616619\end{rationale}
    617620
     
    637640
    638641\begin{rationale}
    639 Expression syntax is quoted from the {\c11} standard.
     642Expression syntax is quoted from the \Celeven standard.
    640643The syntax itself defines the precedence and associativity of operators.
    641644The sections are arranged in decreasing order of precedence, with all operators in a section having the same precedence.
     
    665668The \Index{valid interpretation} of an \nonterm{identifier} are given by the visible\index{visible} declarations of the identifier.
    666669
    667 A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by {\c11}.
     670A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by \Celeven.
    668671The predefined integer identifiers ``©1©'' and ``©0©'' have the integer values 1 and 0, respectively.
    669672The other two predefined ``©0©'' identifiers are bound to polymorphic pointer values that, when specialized\index{specialization} with a data type or function type respectively, produce a null pointer of that type.
     
    11131116forall( otype T ) T restrict * ?++( T restrict *restrict volatile * );
    11141117\end{lstlisting} with ©T© inferred to be ©float *©.
    1115 This looks odd, because {\c11} contains a constraint that requires restrict-qualified types to be pointer-to-object types, and ©T© is not syntactically a pointer type. \CFA loosens the constraint.
     1118This looks odd, because \Celeven contains a constraint that requires restrict-qualified types to be pointer-to-object types, and ©T© is not syntactically a pointer type. \CFA loosens the constraint.
    11161119\end{enumerate}
    11171120\end{rationale}
     
    14771480
    14781481\begin{rationale}
    1479 {\c11} does not include conversions from the \Index{real type}s to \Index{complex type}s in the \Index{usual arithmetic conversion}s.  Instead it specifies conversion of the result of binary operations on arguments from mixed type domains. \CFA's predefined operators match that pattern.
     1482\Celeven does not include conversions from the \Index{real type}s to \Index{complex type}s in the \Index{usual arithmetic conversion}s.  Instead it specifies conversion of the result of binary operations on arguments from mixed type domains. \CFA's predefined operators match that pattern.
    14801483\end{rationale}
    14811484
     
    15061509
    15071510\begin{rationale}
    1508 {\c11} defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of ©int©.
     1511\Celeven defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of ©int©.
    15091512If ©s© is a ©short int©, ``©s *s©'' does not have type ©short int©;
    15101513it is treated as ``©( (int)s ) * ( (int)s )©'', and has type ©int©. \CFA matches that pattern;
     
    15191522\end{lstlisting}
    15201523Since \CFA does not define a multiplication operator for ©short int©, ©square( s )© is treated as ©square( (int)s )©, and the result has type ©int©.
    1521 This is mildly surprising, but it follows the {\c11} operator pattern.
     1524This is mildly surprising, but it follows the \Celeven operator pattern.
    15221525
    15231526A more troubling example is
     
    16171620©ptrdiff_t© is an implementation-defined identifier defined in ©<stddef.h>© that is synonymous with a signed integral type that is large enough to hold the difference between two pointers.
    16181621It seems reasonable to use it for pointer addition as well. (This is technically a difference between \CFA and C, which only specifies that pointer addition uses an \emph{integral} argument.) Hence it is also used for subscripting, which is defined in terms of pointer addition.
    1619 The {\c11} standard uses ©size_t© in several cases where a library function takes an argument that is used as a subscript, but ©size_t© is unsuitable here because it is an unsigned type.
     1622The \Celeven standard uses ©size_t© in several cases where a library function takes an argument that is used as a subscript, but ©size_t© is unsuitable here because it is an unsigned type.
    16201623\end{rationale}
    16211624
     
    19301933\end{lstlisting}
    19311934The logical expression calls the ©Rational© inequality operator, passing it ©*rp© and the ©Rational 0©, and getting a 1 or 0 as a result.
    1932 In contrast, {\CC} would apply a programmer-defined ©Rational©-to-©int© conversion to ©*rp© in the equivalent situation.
     1935In contrast, \CC would apply a programmer-defined ©Rational©-to-©int© conversion to ©*rp© in the equivalent situation.
    19331936The conversion to ©int© would produce a general integer value, which is unfortunate, and possibly dangerous if the conversion was not written with this situation in mind.
    19341937\end{rationale}
     
    26262629\begin{itemize}
    26272630\item a typedef name may be redefined to denote the same type as it currently does, provided that type is not a variably modified type;
    2628 \item tags may be redeclared as specified in section 6.7.2.3 of the {\c11} standard.
     2631\item tags may be redeclared as specified in section 6.7.2.3 of the \Celeven standard.
    26292632\end{itemize}
    26302633\begin{rationale}
    2631 This constraint adds the phrase ``with compatible types'' to the {\c11} constraint, to allow overloading.
     2634This constraint adds the phrase ``with compatible types'' to the \Celeven constraint, to allow overloading.
    26322635\end{rationale}
    26332636
    26342637An identifier declared by a type declaration shall not be redeclared as a parameter in a function definition whose declarator includes an identifier list.
    26352638\begin{rationale}
    2636 This restriction echos {\c11}'s ban on the redeclaration of typedef names as parameters.
     2639This restriction echos \Celeven's ban on the redeclaration of typedef names as parameters.
    26372640This avoids an ambiguity between old-style function declarations and new-style function prototypes:
    26382641\begin{lstlisting}
     
    26612664
    26622665\semantics
    2663 \CFA extends the {\c11} definition of \define{anonymous structure} to include structure specifiers with tags, and extends the {\c11} definition of \define{anonymous union} to include union specifiers with tags.
     2666\CFA extends the \Celeven definition of \define{anonymous structure} to include structure specifiers with tags, and extends the \Celeven definition of \define{anonymous union} to include union specifiers with tags.
    26642667\begin{rationale}
    26652668This extension imitates an extension in the Plan 9 C compiler \cite{Thompson90new}.
     
    28542857
    28552858\begin{rationale}
    2856 ©lvalue© provides some of the functionality of {\CC}'s ``©T&©'' ( reference to object of type ©T©) type.
    2857 Reference types have four uses in {\CC}.
     2859©lvalue© provides some of the functionality of \CC's ``©T&©'' ( reference to object of type ©T©) type.
     2860Reference types have four uses in \CC.
    28582861\begin{itemize}
    28592862\item
     
    28622865\item
    28632866A reference can be used to define an alias for a complicated lvalue expression, as a way of getting some of the functionality of the Pascal ©with© statement.
    2864 The following {\CC} code gives an example.
     2867The following \CC code gives an example.
    28652868\begin{lstlisting}
    28662869{
     
    28742877A reference parameter can be used to allow a function to modify an argument without forcing the caller to pass the address of the argument.
    28752878This is most useful for user-defined assignment operators.
    2876 In {\CC}, plain assignment is done by a function called ``©operator=©'', and the two expressions
     2879In \CC, plain assignment is done by a function called ``©operator=©'', and the two expressions
    28772880\begin{lstlisting}
    28782881a = b;
     
    28872890\item
    28882891References to \Index{const-qualified} types can be used instead of value parameters.  Given the
    2889 {\CC} function call ``©fiddle( a_thing )©'', where the type of ©a_thing© is
     2892\CC function call ``©fiddle( a_thing )©'', where the type of ©a_thing© is
    28902893©Thing©, the type of ©fiddle© could be either of
    28912894\begin{lstlisting}
     
    32163219The Simula class \cite{SIMULA87} is essentially a record type.
    32173220Since the only operations on a record are member selection and assignment, which can not be overloaded, there is never any ambiguity as to whether the abstraction or the implementation view is being used.
    3218 In {\CC}
     3221In \CC
    32193222\cite{C++}, operations on class instances include assignment and ``©&©'', which can be overloaded.
    32203223A ``scope resolution'' operator can be used inside the class to specify whether the abstract or implementation version of the operation should be used.
     
    35483551\subsection{Predefined macro names}
    35493552
    3550 The implementation shall define the macro names ©__LINE__©, ©__FILE__©, ©__DATE__©, and ©__TIME__©, as in the {\c11} standard.
     3553The implementation shall define the macro names ©__LINE__©, ©__FILE__©, ©__DATE__©, and ©__TIME__©, as in the \Celeven standard.
    35513554It shall not define the macro name ©__STDC__©.
    35523555
     
    36343637\subsection{Pointer and array types}
    36353638
    3636 Array types can barely be said to exist in {\c11}, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression ``©a[i]©'' is equivalent to the dereferencing expression ``©(*( a+( i )))©''.
     3639Array types can barely be said to exist in \Celeven, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression ``©a[i]©'' is equivalent to the dereferencing expression ``©(*( a+( i )))©''.
    36373640Technically, pointer arithmetic and pointer comparisons other than ``©==©'' and ``©!=©'' are only defined for pointers to array elements, but the type system does not enforce those restrictions.
    36383641Consequently, there is no need for a separate ``array type'' specification.
     
    37123715Different operators often have related meanings;
    37133716for instance, in C, ``©+©'', ``©+=©'', and the two versions of ``©++©'' perform variations of addition.
    3714 Languages like {\CC} and Ada allow programmers to define operators for new types, but do not require that these relationships be preserved, or even that all of the operators be implemented.
     3717Languages like \CC and Ada allow programmers to define operators for new types, but do not require that these relationships be preserved, or even that all of the operators be implemented.
    37153718Completeness and consistency is left to the good taste and discretion of the programmer.
    37163719It is possible to encourage these attributes by providing generic operator functions, or member functions of abstract classes, that are defined in terms of other, related operators.
     
    38233826\end{theindex}
    38243827
     3828
    38253829\end{document}
    38263830
  • doc/rob_thesis/intro.tex

    r9c951e3 rb1e63ac5  
    33%======================================================================
    44
    5 \section{\CFA Background}
     5\section{\protect\CFA Background}
    66\label{s:background}
    77\CFA \footnote{Pronounced ``C-for-all'', and written \CFA or Cforall.} is a modern non-object-oriented extension to the C programming language.
     
    370370    \end{tabular}
    371371  \end{center}
    372   \caption{\label{table:types} The different kinds of type parameters in \CFA}
     372  \caption{\label{table:types} The different kinds of type parameters in \protect\CFA}
    373373\end{table}
    374374
  • doc/rob_thesis/thesis.tex

    r9c951e3 rb1e63ac5  
    6666% ,monochrome % toggle black and white mode
    6767}{xcolor}
     68\PassOptionsToPackage{pdftex}{graphicx}
    6869\documentclass[letterpaper,12pt,titlepage,oneside,final]{book}
    6970
  • doc/user/pointer2.fig

    r9c951e3 rb1e63ac5  
    88-2
    991200 2
     106 1125 2100 3525 2400
    10112 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
    11          1500 1950 1950 1950 1950 2250 1500 2250 1500 1950
     12         1500 2100 1950 2100 1950 2400 1500 2400 1500 2100
     132 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
     14         2700 2100 3150 2100 3150 2400 2700 2400 2700 2100
     154 2 0 100 0 4 10 0.0000 2 120 270 1425 2400 104\001
     164 2 0 100 0 4 10 0.0000 2 120 90 1425 2225 y\001
     174 0 0 100 0 4 10 0.0000 2 120 165 2025 2300 int\001
     184 2 0 100 0 4 10 0.0000 2 120 270 2625 2400 112\001
     194 2 0 100 0 4 10 0.0000 2 150 180 2625 2225 p2\001
     204 1 0 100 0 4 10 0.0000 2 120 90 1725 2300 3\001
     214 0 0 100 0 4 10 0.0000 2 120 270 3225 2300 int *\001
     224 1 0 100 0 4 10 0.0000 2 120 270 2925 2300 100\001
     23-6
    12242 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
    1325         1500 1500 1950 1500 1950 1800 1500 1800 1500 1500
    14262 1 0 1 4 7 100 -1 -1 0.000 0 0 -1 1 0 2
    1527        1 1 1.00 45.00 90.00
    16          2700 1800 1950 1950
     28         2700 1800 1950 2100
    17292 1 0 1 4 7 50 -1 -1 0.000 0 0 -1 1 0 2
    1830        1 1 1.00 45.00 90.00
    19          2700 1950 1950 1800
    20 2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
    21          2700 1950 3150 1950 3150 2250 2700 2250 2700 1950
     31         2700 2100 1950 1800
    22322 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
    2333         2700 1500 3150 1500 3150 1800 2700 1800 2700 1500
    24342 1 0 1 4 7 100 -1 -1 0.000 0 0 -1 1 0 2
    2535        1 1 1.00 45.00 90.00
    26          3900 1800 3150 1950
     36         3900 1800 3150 2100
    27372 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
    2838         3900 1500 4350 1500 4350 1800 3900 1800 3900 1500
    29 4 2 0 100 0 4 10 0.0000 2 120 270 1425 2250 104\001
    30394 2 0 100 0 4 10 0.0000 2 120 270 1425 1800 100\001
    31404 2 0 100 0 4 10 0.0000 2 90 90 1425 1625 x\001
    32 4 2 0 100 0 4 10 0.0000 2 120 90 1425 2075 y\001
    33 4 0 0 100 0 4 10 0.0000 2 120 165 2025 2150 int\001
    34414 0 0 100 0 4 10 0.0000 2 120 165 2025 1700 int\001
    35 4 2 0 100 0 4 10 0.0000 2 120 270 2625 2250 112\001
    36 4 2 0 100 0 4 10 0.0000 2 150 180 2625 2075 p2\001
    37424 2 0 100 0 4 10 0.0000 2 120 270 2625 1800 108\001
    38434 2 0 100 0 4 10 0.0000 2 150 180 2625 1625 p1\001
    39 4 1 0 100 0 4 10 0.0000 2 120 90 1725 2150 3\001
    40444 1 0 100 0 4 10 0.0000 2 120 90 1725 1700 3\001
    41 4 0 0 100 0 4 10 0.0000 2 120 270 3225 2150 int *\001
    42454 0 0 100 0 4 10 0.0000 2 120 270 3225 1700 int *\001
    43464 2 0 100 0 4 10 0.0000 2 120 270 3825 1800 116\001
    44474 2 0 100 0 4 10 0.0000 2 150 180 3825 1625 p3\001
    45 4 1 0 100 0 4 10 0.0000 2 120 270 2925 2150 100\001
    46484 1 0 100 0 4 10 0.0000 2 120 270 2925 1700 104\001
    47494 1 0 100 0 4 10 0.0000 2 120 270 4125 1700 112\001
  • doc/user/user.tex

    r9c951e3 rb1e63ac5  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon May 15 18:29:58 2017
    14 %% Update Count     : 1598
     13%% Last Modified On : Fri Jun 16 12:00:01 2017
     14%% Update Count     : 2433
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    4343\usepackage[pagewise]{lineno}
    4444\renewcommand{\linenumberfont}{\scriptsize\sffamily}
    45 \input{common}                                          % bespoke macros used in the document
     45\input{common}                                          % common CFA document macros
    4646\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
    4747\usepackage{breakurl}
     
    9494\author{
    9595\huge \CFA Team \medskip \\
    96 \Large Peter A. Buhr, Richard Bilson, Thierry Delisle, \smallskip \\
     96\Large Andrew Beach, Richard Bilson, Peter A. Buhr, Thierry Delisle, \smallskip \\
    9797\Large Glen Ditchfield, Rodolfo G. Esteves, Aaron Moss, Rob Schluntz
    9898}% author
     
    110110\renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}}
    111111\pagenumbering{roman}
    112 \linenumbers                                            % comment out to turn off line numbering
     112%\linenumbers                                            % comment out to turn off line numbering
    113113
    114114\maketitle
     
    135135
    136136\CFA{}\index{cforall@\CFA}\footnote{Pronounced ``\Index*{C-for-all}'', and written \CFA, CFA, or \CFL.} is a modern general-purpose programming-language, designed as an evolutionary step forward for the C programming language.
    137 The syntax of the \CFA language builds from C, and should look immediately familiar to C/\Index*[C++]{\CC} programmers.
    138 % Any language feature that is not described here can be assumed to be using the standard C11 syntax.
     137The syntax of the \CFA language builds from C, and should look immediately familiar to C/\Index*[C++]{\CC{}} programmers.
     138% Any language feature that is not described here can be assumed to be using the standard \Celeven syntax.
    139139\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 C performance.
    140 Like C, \CFA is a statically typed, procedural 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.
     140Like C, \CFA is a statically typed, procedural 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.
    141141The primary new features include parametric-polymorphic routines and types, exceptions, concurrency, and modules.
    142142
     
    147147instead, a programmer evolves an existing C program into \CFA by incrementally incorporating \CFA features.
    148148New programs can be written in \CFA using a combination of C and \CFA features.
    149 \Index*[C++]{\CC} had a similar goal 30 years ago, but currently has the disadvantages of 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.
     149\Index*[C++]{\CC{}} had a similar goal 30 years ago, but currently has the disadvantages of 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.
    150150In contrast, \CFA has 30 years of hindsight and a clean starting point.
    151151
    152 Like \Index*[C++]{\CC}, there may be both an old and new ways to achieve the same effect.
    153 For example, the following programs compare the \CFA and C I/O mechanisms.
     152Like \Index*[C++]{\CC{}}, there may be both an old and new ways to achieve the same effect.
     153For example, the following programs compare the \CFA, C, and \CC I/O mechanisms, where the programs output the same result.
    154154\begin{quote2}
    155155\begin{tabular}{@{}l@{\hspace{1.5em}}l@{\hspace{1.5em}}l@{}}
    156156\multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{\CFA}}      & \multicolumn{1}{c}{\textbf{C}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
    157157\begin{cfa}
    158 #include <fstream>
     158#include <fstream>§\indexc{fstream}§
    159159
    160160int main( void ) {
     
    165165&
    166166\begin{lstlisting}
    167 #include <stdio.h>
     167#include <stdio.h>§\indexc{stdio.h}§
    168168
    169169int main( void ) {
     
    174174&
    175175\begin{lstlisting}
    176 #include <iostream>
     176#include <iostream>§\indexc{iostream}§
    177177using namespace std;
    178178int main() {
     
    183183\end{tabular}
    184184\end{quote2}
    185 The programs output the same result.
    186 While the \CFA I/O looks similar to the \Index*[C++]{\CC} output style, there are important differences, such as automatic spacing between variables as in \Index*{Python} (see~\VRef{s:IOLibrary}).
    187 
    188 This document is a user manual for the \CFA programming language, targeted at \CFA programmers.
     185While 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}).
     186
     187This document is a programmer reference-manual for the \CFA programming language.
     188The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of each feature.
     189The manual does not teach programming, i.e., how to combine the new constructs to build complex programs.
     190A 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.
    189191Implementers may refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
    190 In its current state, this document covers the intended core features of the language.
    191192Changes to the syntax and additional features are expected to be included in later revisions.
    192193
     
    198199Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    199200For system programming, where direct access to hardware and dealing with real-time issues is a requirement, C is usually the language of choice.
    200 The TIOBE index~\cite{TIOBE} for March 2016 showed the following programming-language popularity: \Index*{Java} 20.5\%, C 14.5\%, \Index*[C++]{\CC} 6.7\%, \Csharp 4.3\%, \Index*{Python} 4.3\%, where the next 50 languages are less than 3\% each with a long tail.
     201The 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.
    201202As well, for 30 years, C has been the number 1 and 2 most popular programming language:
    202203\begin{center}
     
    217218
    218219As stated, the goal of the \CFA project is to engineer modern language features into C in an evolutionary rather than revolutionary way.
    219 \CC~\cite{c++,ANSI14:C++} is an example of a similar project;
     220\CC~\cite{C++14,C++} is an example of a similar project;
    220221however, it largely extended the language, and did not address many existing problems.\footnote{%
    221222Two important existing problems addressed were changing the type of character literals from ©int© to ©char© and enumerator from ©int© to the type of its enumerators.}
     
    226227These costs can be prohibitive for many companies with a large software base in C/\CC, and a significant number of programmers requiring retraining to a new programming language.
    227228
    228 The result of this project is a language that is largely backwards compatible with \Index*{C11}~\cite{C11}, but fixing some of the well known C problems and containing many modern language features.
     229The result of this project is a language that is largely backwards compatible with \Index*[C11]{\Celeven{}}~\cite{C11}, but fixing some of the well known C problems and containing many modern language features.
    229230Without significant extension to the C programming language, it is becoming unable to cope with the needs of modern programming problems and programmers;
    230231as a result, it will fade into disuse.
    231232Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern programming language.
    232 While \Index*{C11} made a few simple extensions to the language, nothing was added to address existing problems in the language or to augment the language with modern language features.
     233While \Index*[C11]{\Celeven{}} made a few simple extensions to the language, nothing was added to address existing problems in the language or to augment the language with modern language features.
    233234While some may argue that modern language features may make C complex and inefficient, it is clear a language without modern capabilities is insufficient for the advanced programming problems existing today.
    234235
     
    244245int forty_two = identity( 42 );                 §\C{// T is bound to int, forty\_two == 42}§
    245246\end{lstlisting}
    246 % extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC} approach of object-oriented extensions.
     247% extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions.
    247248\CFA{}\hspace{1pt}'s polymorphism was originally formalized by Ditchfiled~\cite{Ditchfield92}, and first implemented by Bilson~\cite{Bilson03}.
    248249However, at that time, there was little interesting in extending C, so work did not continue.
     
    263264A simple example is leveraging the existing type-unsafe (©void *©) C ©bsearch© to binary search a sorted floating-point array:
    264265\begin{lstlisting}
    265 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size,
     266void * bsearch( const void * key, const void * base, size_t dim, size_t size,
    266267                                int (* compar)( const void *, const void * ));
    267268
     
    341342The 1999 C standard plus GNU extensions.
    342343\item
     344{\lstset{deletekeywords={inline}}
    343345\Indexc{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{©-fgnu89-inline©}}
    344346Use the traditional GNU semantics for inline routines in C99 mode, which allows inline routines in header files.
     347}%
    345348\end{description}
    346349The following new \CFA options are available:
     
    413416\begin{cfa}
    414417#ifndef __CFORALL__
    415 #include <stdio.h>                                              §\C{// C header file}§
     418#include <stdio.h>§\indexc{stdio.h}§    §\C{// C header file}§
    416419#else
    417 #include <fstream>                                              §\C{// \CFA header file}§
     420#include <fstream>§\indexc{fstream}§    §\C{// \CFA header file}§
    418421#endif
    419422\end{cfa}
     
    451454the type suffixes ©U©, ©L©, etc. may start with an underscore ©1_U©, ©1_ll© or ©1.0E10_f©.
    452455\end{enumerate}
    453 It is significantly easier to read and enter long constants when they are broken up into smaller groupings (most cultures use comma or period among digits for the same purpose).
     456It is significantly easier to read and enter long constants when they are broken up into smaller groupings (many cultures use comma and/or period among digits for the same purpose).
    454457This extension is backwards compatible, matches with the use of underscore in variable names, and appears in \Index*{Ada} and \Index*{Java} 8.
    455458
     
    461464\begin{cfa}
    462465int ®`®otype®`® = 3;                    §\C{// make keyword an identifier}§
    463 double ®`®choose®`® = 3.5;
    464 \end{cfa}
    465 Programs can be converted easily by enclosing keyword identifiers in backquotes, and the backquotes can be removed later when the identifier name is changed to a non-keyword name.
     466double ®`®forall®`® = 3.5;
     467\end{cfa}
     468Existing 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.
    466469\VRef[Figure]{f:InterpositionHeaderFile} shows how clashes in C header files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©:
    467470
     
    470473// include file uses the CFA keyword "otype".
    471474#if ! defined( otype )                  §\C{// nesting ?}§
    472 #define otype `otype`
     475#define otype ®`®otype®`®               §\C{// make keyword an identifier}§
    473476#define __CFA_BFD_H__
    474477#endif // ! otype
     
    494497\begin{tabular}{@{}ll@{}}
    495498\begin{cfa}
    496 int *x[5]
     499int * x[5]
    497500\end{cfa}
    498501&
     
    505508For example, a routine returning a \Index{pointer} to an array of integers is defined and used in the following way:
    506509\begin{cfa}
    507 int (*f())[5] {...};                    §\C{
    508 ... (*f())[3] += 1;
     510int ®(*®f®())[®5®]® {...};                              §\C{definition
     511 ... ®(*®f®())[®3®]® += 1;                              §\C{usage}§
    509512\end{cfa}
    510513Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}).
     
    513516\CFA provides its own type, variable and routine declarations, using a different syntax.
    514517The new declarations place qualifiers to the left of the base type, while C declarations place qualifiers to the right of the base type.
    515 In the following example, \R{red} is for the base type and \B{blue} is for the qualifiers.
    516 The \CFA declarations move the qualifiers to the left of the base type, i.e., move the blue to the left of the red, while the qualifiers have the same meaning but are ordered left to right to specify a variable's type.
     518In the following example, \R{red} is the base type and \B{blue} is qualifiers.
     519The \CFA declarations move the qualifiers to the left of the base type, \ie move the blue to the left of the red, while the qualifiers have the same meaning but are ordered left to right to specify a variable's type.
    517520\begin{quote2}
    518521\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
     
    531534\end{tabular}
    532535\end{quote2}
    533 The only exception is bit field specification, which always appear to the right of the base type.
     536The only exception is \Index{bit field} specification, which always appear to the right of the base type.
    534537% Specifically, the character ©*© is used to indicate a pointer, square brackets ©[©\,©]© are used to represent an array or function return value, and parentheses ©()© are used to indicate a routine parameter.
    535538However, unlike C, \CFA type declaration tokens are distributed across all variables in the declaration list.
     
    580583\begin{cfa}
    581584int z[ 5 ];
    582 char *w[ 5 ];
    583 double (*v)[ 5 ];
     585char * w[ 5 ];
     586double (* v)[ 5 ];
    584587struct s {
    585588        int f0:3;
    586         int *f1;
    587         int *f2[ 5 ]
     589        int * f1;
     590        int * f2[ 5 ]
    588591};
    589592\end{cfa}
     
    634637\begin{cfa}
    635638int extern x[ 5 ];
    636 const int static *y;
     639const int static * y;
    637640\end{cfa}
    638641&
     
    644647\end{quote2}
    645648
    646 Unsupported are K\&R C declarations where the base type defaults to ©int©, if no type is specified,\footnote{
    647 At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and type name~\cite[\S~6.7.2(2)]{C11}}
    648 \eg:
    649 \begin{cfa}
    650 x;                                                              §\C{// int x}§
    651 *y;                                                             §\C{// int *y}§
    652 f( p1, p2 );                                    §\C{// int f( int p1, int p2 );}§
    653 f( p1, p2 ) {}                                  §\C{// int f( int p1, int p2 ) {}}§
    654 \end{cfa}
     649The new declaration syntax can be used in other contexts where types are required, \eg casts and the pseudo-routine ©sizeof©:
     650\begin{quote2}
     651\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
     652\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     653\begin{cfa}
     654y = (®* int®)x;
     655i = sizeof(®[ 5 ] * int®);
     656\end{cfa}
     657&
     658\begin{cfa}
     659y = (®int *®)x;
     660i = sizeof(®int * [ 5 ]®);
     661\end{cfa}
     662\end{tabular}
     663\end{quote2}
    655664
    656665Finally, new \CFA declarations may appear together with C declarations in the same program block, but cannot be mixed within a specific declaration.
     
    659668
    660669
    661 \section{Pointer / Reference}
     670\section{Pointer/Reference}
    662671
    663672C provides a \newterm{pointer type};
    664673\CFA adds a \newterm{reference type}.
    665 Both types contain an \newterm{address}, which is normally a location in memory.
    666 Special addresses are used to denote certain states or access co-processor memory.
    667 By convention, no variable is placed at address 0, so addresses like 0, 1, 2, 3 are often used to denote no-value or other special states.
    668 Often dereferencing a special state causes a \Index{memory fault}, so checking is necessary during execution.
    669 If the programming language assigns addresses, a program's execution is \Index{sound}, i.e., all addresses are to valid memory locations.
    670 C allows programmers to assign addresses, so there is the potential for incorrect addresses, both inside and outside of the computer address-space.
    671 
    672 Program variables are implicit pointers to memory locations generated by the compiler and automatically dereferenced, as in:
     674These types may be derived from an object or routine type, called the \newterm{referenced type}.
     675Objects of these types contain an \newterm{address}, which is normally a location in memory, but may also address memory-mapped registers in hardware devices.
     676An integer constant expression with the value 0, or such an expression cast to type ©void *©, is called a \newterm{null-pointer constant}.\footnote{
     677One way to conceptualize the null pointer is that no variable is placed at this address, so the null-pointer address can be used to denote an uninitialized pointer/reference object;
     678\ie the null pointer is guaranteed to compare unequal to a pointer to any object or routine.}
     679An address is \newterm{sound}, if it points to a valid memory location in scope, \ie within the program's execution-environment and has not been freed.
     680Dereferencing an \newterm{unsound} address, including the null pointer, is \Index{undefined}, often resulting in a \Index{memory fault}.
     681
     682A program \newterm{object} is a region of data storage in the execution environment, the contents of which can represent values.
     683In most cases, objects are located in memory at an address, and the variable name for an object is an implicit address to the object generated by the compiler and automatically dereferenced, as in:
    673684\begin{quote2}
    674 \begin{tabular}{@{}lll@{}}
     685\begin{tabular}{@{}ll@{\hspace{2em}}l@{}}
    675686\begin{cfa}
    676687int x;
     
    691702\end{quote2}
    692703where the right example is how the compiler logically interprets the variables in the left example.
    693 Since a variable name only points to one location during its lifetime, it is an \Index{immutable} \Index{pointer};
    694 hence, variables ©x© and ©y© are constant pointers in the compiler interpretation.
    695 In general, variable addresses are stored in instructions instead of loaded independently, so an instruction fetch implicitly loads a variable's address.
     704Since a variable name only points to one address during its lifetime, it is an \Index{immutable} \Index{pointer};
     705hence, the implicit type of pointer variables ©x© and ©y© are constant pointers in the compiler interpretation.
     706In general, variable addresses are stored in instructions instead of loaded from memory, and hence may not occupy storage.
     707These approaches are contrasted in the following:
    696708\begin{quote2}
    697709\begin{tabular}{@{}l|l@{}}
     710\multicolumn{1}{c|}{explicit variable address} & \multicolumn{1}{c}{implicit variable address} \\
     711\hline
    698712\begin{cfa}
    699713lda             r1,100                  // load address of x
    700 ld              r2,(r1)                   // load value of x
     714ld               r2,(r1)                  // load value of x
    701715lda             r3,104                  // load address of y
    702 st              r2,(r3)                   // store x into y
     716st               r2,(r3)                  // store x into y
    703717\end{cfa}
    704718&
     
    711725\end{tabular}
    712726\end{quote2}
    713 Finally, the immutable nature of a variable's address and the fact that there is no storage for a variable address means pointer assignment\index{pointer!assignment}\index{assignment!pointer} is impossible.
    714 Therefore, the expression ©x = y© only has one meaning, ©*x = *y©, i.e., manipulate values, which is why explicitly writing the dereferences is unnecessary even though it occurs implicitly as part of instruction decoding.
    715 
    716 A \Index{pointer}/\Index{reference} is a generalization of a variable name, i.e., a mutable address that can point to more than one memory location during its lifetime.
    717 (Similarly, an integer variable can contain multiple integer literals during its lifetime versus an integer constant representing a single literal during its lifetime and may not occupy storage as the literal is embedded directly into instructions.)
     727Finally, the immutable nature of a variable's address and the fact that there is no storage for the variable pointer means pointer assignment\index{pointer!assignment}\index{assignment!pointer} is impossible.
     728Therefore, the expression ©x = y© has only one meaning, ©*x = *y©, \ie manipulate values, which is why explicitly writing the dereferences is unnecessary even though it occurs implicitly as part of \Index{instruction decoding}.
     729
     730A \Index{pointer}/\Index{reference} object is a generalization of an object variable-name, \ie a mutable address that can point to more than one memory location during its lifetime.
     731(Similarly, an integer variable can contain multiple integer literals during its lifetime versus an integer constant representing a single literal during its lifetime, and like a variable name, may not occupy storage if the literal is embedded directly into instructions.)
    718732Hence, a pointer occupies memory to store its current address, and the pointer's value is loaded by dereferencing, \eg:
    719733\begin{quote2}
    720 \begin{tabular}{@{}ll@{}}
     734\begin{tabular}{@{}l@{\hspace{2em}}l@{}}
    721735\begin{cfa}
    722736int x, y, ®*® p1, ®*® p2, ®**® p3;
     
    727741\end{cfa}
    728742&
    729 \raisebox{-0.45\totalheight}{\input{pointer2.pstex_t}}
     743\raisebox{-0.5\totalheight}{\input{pointer2.pstex_t}}
    730744\end{tabular}
    731745\end{quote2}
    732746
    733 Notice, an address has a duality\index{address!duality}: a location in memory or the value at that location.
    734 In many cases, a compiler might be able to infer the meaning:
     747Notice, an address has a \Index{duality}\index{address!duality}: a location in memory or the value at that location.
     748In many cases, a compiler might be able to infer the best meaning for these two cases.
     749For example, \Index*{Algol68}~\cite{Algol68} infers pointer dereferencing to select the best meaning for each pointer usage
    735750\begin{cfa}
    736751p2 = p1 + x;                                    §\C{// compiler infers *p2 = *p1 + x;}§
    737752\end{cfa}
    738 because adding the arbitrary integer value in ©x© to the address of ©p1© and storing the resulting address into ©p2© is an unlikely operation.
    739 \Index*{Algol68}~\cite{Algol68} inferences pointer dereferencing to select the best meaning for each pointer usage.
    740 However, in C, the following cases are ambiguous, especially with pointer arithmetic:
    741 \begin{cfa}
    742 p1 = p2;                                                §\C{// p1 = p2\ \ or\ \ *p1 = *p2}§
    743 p1 = p1 + 1;                                    §\C{// p1 = p1 + 1\ \ or\ \ *p1 = *p1 + 1}§
    744 \end{cfa}
    745 
    746 Most languages pick one meaning as the default and the programmer explicitly indicates the other meaning to resolve the address-duality ambiguity\index{address! ambiguity}.
    747 In C, the default meaning for pointers is to manipulate the pointer's address and the pointed-to value is explicitly accessed by the dereference operator ©*©.
     753Algol68 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.
     754Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices.
     755
     756Rather than inferring dereference, most programming languages pick one implicit dereferencing semantics, and the programmer explicitly indicates the other to resolve address-duality.
     757In C, objects of pointer type always manipulate the pointer object's address:
     758\begin{cfa}
     759p1 = p2;                                                §\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}§
     760p2 = p1 + x;                                    §\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}§
     761\end{cfa}
     762even though the assignment to ©p2© is likely incorrect, and the programmer probably meant:
    748763\begin{cfa}
    749764p1 = p2;                                                §\C{// pointer address assignment}§
    750 *p1 = *p1 + 1;                                  §\C{// pointed-to value assignment / operation}§
    751 \end{cfa}
    752 which works well for situations where manipulation of addresses is the primary meaning and data is rarely accessed, such as storage management (©malloc©/©free©).
     765®*®p2 = ®*®p1 + x;                              §\C{// pointed-to value assignment / operation}§
     766\end{cfa}
     767The 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©).
    753768
    754769However, in most other situations, the pointed-to value is requested more often than the pointer address.
     
    762777\end{cfa}
    763778
    764 To switch the default meaning for an address requires a new kind of pointer, called a \newterm{reference} denoted by ©&©.
     779To support this common case, a reference type is introduced in \CFA, denoted by ©&©, which is the opposite dereference semantics to a pointer type, making the value at the pointed-to location the implicit semantics for dereferencing (similar but not the same as \CC \Index{reference type}s).
    765780\begin{cfa}
    766781int x, y, ®&® r1, ®&® r2, ®&&® r3;
     
    773788Except for auto-dereferencing by the compiler, this reference example is the same as the previous pointer example.
    774789Hence, a reference behaves like the variable name for the current variable it is pointing-to.
    775 The simplest way to understand a reference is to imagine the compiler inserting a dereference operator before the reference variable for each reference qualifier in a declaration, \eg:
    776 \begin{cfa}
    777 r2 = ((r1 + r2) * (r3 - r1)) / (r3 - 15);
    778 \end{cfa}
    779 is rewritten as:
     790One way to conceptualize a reference is via a rewrite rule, where the compiler inserts a dereference operator before the reference variable for each reference qualifier in a declaration, so the previous example becomes:
    780791\begin{cfa}
    781792®*®r2 = ((®*®r1 + ®*®r2) ®*® (®**®r3 - ®*®r1)) / (®**®r3 - 15);
    782793\end{cfa}
    783 When a reference operation appears beside a dereference operation, \eg ©&*©, they cancel out.\footnote{
     794When a reference operation appears beside a dereference operation, \eg ©&*©, they cancel out.
     795However, in C, the cancellation always yields a value (\Index{rvalue}).\footnote{
    784796The unary ©&© operator yields the address of its operand.
    785797If the operand has type ``type'', the result has type ``pointer to type''.
    786798If the operand is the result of a unary ©*© operator, neither that operator nor the ©&© operator is evaluated and the result is as if both were omitted, except that the constraints on the operators still apply and the result is not an lvalue.~\cite[\S~6.5.3.2--3]{C11}}
    787 Hence, assigning to a reference requires the address of the reference variable (\Index{lvalue}):
    788 \begin{cfa}
    789 (&®*®)r1 = &x;                                  §\C{// (\&*) cancel giving variable r1 not variable pointed-to by r1}§
     799For a \CFA reference type, the cancellation on the left-hand side of assignment leaves the reference as an address (\Index{lvalue}):
     800\begin{cfa}
     801(&®*®)r1 = &x;                                  §\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}§
    790802\end{cfa}
    791803Similarly, the address of a reference can be obtained for assignment or computation (\Index{rvalue}):
    792804\begin{cfa}
    793 (&(&®*®)®*®)r3 = &(&®*®)r2;             §\C{// (\&*) cancel giving address of r2, (\&(\&*)*) cancel giving variable r3}§
    794 \end{cfa}
    795 Cancellation\index{cancellation!pointer/reference}\index{pointer!cancellation} works to arbitrary depth, and pointer and reference values are interchangeable because both contain addresses.
     805(&(&®*®)®*®)r3 = &(&®*®)r2;             §\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}§
     806\end{cfa}
     807Cancellation\index{cancellation!pointer/reference}\index{pointer!cancellation} works to arbitrary depth.
     808
     809Fundamentally, pointer and reference objects are functionally interchangeable because both contain addresses.
    796810\begin{cfa}
    797811int x, *p1 = &x, **p2 = &p1, ***p3 = &p2,
     
    805819&&&r3 = p3;                                             §\C{// change r3 to p3, (\&(\&(\&*)*)*)r3, 3 cancellations}§
    806820\end{cfa}
    807 Finally, implicit dereferencing and cancellation are a static (compilation) phenomenon not a dynamic one.
    808 That is, all implicit dereferencing and any cancellation is carried out prior to the start of the program, so reference performance is equivalent to pointer performance.
    809 A programmer selects a pointer or reference type solely on whether the address is dereferenced frequently or infrequently, which dictates the amount of direct aid from the compiler;
    810 otherwise, everything else is equal.
    811 
    812 Interestingly, \Index*[C++]{\CC} deals with the address duality by making the pointed-to value the default, and prevent\-ing changes to the reference address, which eliminates half of the duality.
    813 \Index*{Java} deals with the address duality by making address assignment the default and requiring field assignment (direct or indirect via methods), i.e., there is no builtin bit-wise or method-wise assignment, which eliminates half of the duality.
    814 
    815 As for a pointer, a reference may have qualifiers:
    816 \begin{cfa}
    817 const int cx = 5;                               §\C{// cannot change cx;}§
    818 const int & cr = cx;                    §\C{// cannot change what cr points to}§
    819 ®&®cr = &cx;                                    §\C{// can change cr}§
    820 cr = 7;                                                 §\C{// error, cannot change cx}§
    821 int & const rc = x;                             §\C{// must be initialized, \CC reference}§
    822 ®&®rc = &x;                                             §\C{// error, cannot change rc}§
    823 const int & const crc = cx;             §\C{// must be initialized, \CC reference}§
    824 crc = 7;                                                §\C{// error, cannot change cx}§
    825 ®&®crc = &cx;                                   §\C{// error, cannot change crc}§
    826 \end{cfa}
    827 Hence, for type ©& const©, there is no pointer assignment, so ©&rc = &x© is disallowed, and \emph{the address value cannot be ©0© unless an arbitrary pointer is assigned to the reference}, \eg:
    828 \begin{cfa}
    829 int & const r = *0;                             §\C{// where 0 is the int * zero}§
    830 \end{cfa}
    831 Otherwise, the compiler is managing the addresses for type ©& const© not the programmer, and by a programming discipline of only using references with references, address errors can be prevented.
    832 Finally, the position of the ©const© qualifier \emph{after} the pointer/reference qualifier causes confuse for C programmers.
     821Furthermore, both types are equally performant, as the same amount of dereferencing occurs for both types.
     822Therefore, the choice between them is based solely on whether the address is dereferenced frequently or infrequently, which dictates the amount of implicit dereferencing aid from the compiler.
     823
     824As for a pointer type, a reference type may have qualifiers:
     825\begin{cfa}
     826const int cx = 5;                                       §\C{// cannot change cx;}§
     827const int & cr = cx;                            §\C{// cannot change what cr points to}§
     828®&®cr = &cx;                                            §\C{// can change cr}§
     829cr = 7;                                                         §\C{// error, cannot change cx}§
     830int & const rc = x;                                     §\C{// must be initialized}§
     831®&®rc = &x;                                                     §\C{// error, cannot change rc}§
     832const int & const crc = cx;                     §\C{// must be initialized}§
     833crc = 7;                                                        §\C{// error, cannot change cx}§
     834®&®crc = &cx;                                           §\C{// error, cannot change crc}§
     835\end{cfa}
     836Hence, 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}:
     837\begin{cfa}
     838int & const cr = *0;                            §\C{// where 0 is the int * zero}§
     839\end{cfa}
     840Note, constant reference-types do not prevent \Index{addressing errors} because of explicit storage-management:
     841\begin{cfa}
     842int & const cr = *malloc();
     843cr = 5;
     844free( &cr );
     845cr = 7;                                                         §\C{// unsound pointer dereference}§
     846\end{cfa}
     847
     848The position of the ©const© qualifier \emph{after} the pointer/reference qualifier causes confuse for C programmers.
    833849The ©const© qualifier cannot be moved before the pointer/reference qualifier for C style-declarations;
    834 \CFA-style declarations attempt to address this issue:
     850\CFA-style declarations (see \VRef{s:Declarations}) attempt to address this issue:
    835851\begin{quote2}
    836852\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
     
    847863\end{tabular}
    848864\end{quote2}
    849 where the \CFA declaration is read left-to-right (see \VRef{s:Declarations}).
     865where the \CFA declaration is read left-to-right.
     866
     867Finally, like pointers, references are usable and composable with other type operators and generators.
     868\begin{cfa}
     869int w, x, y, z, & ar[3] = { x, y, z }; §\C{// initialize array of references}§
     870&ar[1] = &w;                                            §\C{// change reference array element}§
     871typeof( ar[1] ) p;                                      §\C{// (gcc) is int, i.e., the type of referenced object}§
     872typeof( &ar[1] ) q;                                     §\C{// (gcc) is int \&, i.e., the type of reference}§
     873sizeof( ar[1] ) == sizeof( int );       §\C{// is true, i.e., the size of referenced object}§
     874sizeof( &ar[1] ) == sizeof( int *)      §\C{// is true, i.e., the size of a reference}§
     875\end{cfa}
     876
     877In contrast to \CFA reference types, \Index*[C++]{\CC{}}'s reference types are all ©const© references, preventing changes to the reference address, so only value assignment is possible, which eliminates half of the \Index{address duality}.
     878Also, \CC does not allow \Index{array}s\index{array!reference} of reference\footnote{
     879The reason for disallowing arrays of reference is unknown, but possibly comes from references being ethereal (like a textual macro), and hence, replaceable by the referant object.}
     880\Index*{Java}'s reference types to objects (all Java objects are on the heap) are like C pointers, which always manipulate the address, and there is no (bit-wise) object assignment, so objects are explicitly cloned by shallow or deep copying, which eliminates half of the address duality.
     881
     882
     883\subsection{Initialization}
    850884
    851885\Index{Initialization} is different than \Index{assignment} because initialization occurs on the empty (uninitialized) storage on an object, while assignment occurs on possibly initialized storage of an object.
    852886There are three initialization contexts in \CFA: declaration initialization, argument/parameter binding, return/temporary binding.
    853 For reference initialization (like pointer), the initializing value must be an address (\Index{lvalue}) not a value (\Index{rvalue}).
    854 \begin{cfa}
    855 int * p = &x;                                   §\C{// both \&x and x are possible interpretations}§
    856 int & r = x;                                    §\C{// x unlikely interpretation, because of auto-dereferencing}§
    857 \end{cfa}
    858 Hence, the compiler implicitly inserts a reference operator, ©&©, before the initialization expression.
    859 Similarly, when a reference is used for a parameter/return type, the call-site argument does not require a reference operator.
    860 \begin{cfa}
    861 int & f( int & rp );                    §\C{// reference parameter and return}§
    862 z = f( x ) + f( y );                    §\C{// reference operator added, temporaries needed for call results}§
    863 \end{cfa}
    864 Within routine ©f©, it is possible to change the argument by changing the corresponding parameter, and parameter ©rp© can be locally reassigned within ©f©.
    865 Since ©?+?© takes its arguments by value, the references returned from ©f© are used to initialize compiler generated temporaries with value semantics that copy from the references.
     887Because the object being initialized has no value, there is only one meaningful semantics with respect to address duality: it must mean address as there is no pointed-to value.
     888In contrast, the left-hand side of assignment has an address that has a duality.
     889Therefore, for pointer/reference initialization, the initializing value must be an address not a value.
     890\begin{cfa}
     891int * p = &x;                                           §\C{// assign address of x}§
     892®int * p = x;®                                          §\C{// assign value of x}§
     893int & r = x;                                            §\C{// must have address of x}§
     894\end{cfa}
     895Like 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).
     896Therefore, for safety, this context requires an address, so it is superfluous to require explicitly taking the address of the initialization object, even though the type is incorrect.
     897Note, this is strictly a convenience and safety feature for a programmer.
     898Hence, \CFA allows ©r© to be assigned ©x© because it infers a reference for ©x©, by implicitly inserting a address-of operator, ©&©, and it is an error to put an ©&© because the types no longer match due to the implicit dereference.
     899Unfortunately, C allows ©p© to be assigned with ©&x© (address) or ©x© (value), but most compilers warn about the latter assignment as being potentially incorrect.
     900Similarly, 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.
     901\begin{cfa}
     902int & f( int & r );                                     §\C{// reference parameter and return}§
     903z = f( x ) + f( y );                            §\C{// reference operator added, temporaries needed for call results}§
     904\end{cfa}
     905Within routine ©f©, it is possible to change the argument by changing the corresponding parameter, and parameter ©r© can be locally reassigned within ©f©.
     906Since operator routine ©?+?© takes its arguments by value, the references returned from ©f© are used to initialize compiler generated temporaries with value semantics that copy from the references.
     907\begin{cfa}
     908int temp1 = f( x ), temp2 = f( y );
     909z = temp1 + temp2;
     910\end{cfa}
     911This \Index{implicit referencing} is crucial for reducing the syntactic burden for programmers when using references;
     912otherwise references have the same syntactic  burden as pointers in these contexts.
    866913
    867914When a pointer/reference parameter has a ©const© value (immutable), it is possible to pass literals and expressions.
    868915\begin{cfa}
    869 void f( ®const® int & crp );
    870 void g( ®const® int * cpp );
    871 f( 3 );                   g( &3 );
    872 f( x + y );             g( &(x + y) );
     916void f( ®const® int & cr );
     917void g( ®const® int * cp );
     918f( 3 );                   g( ®&®3 );
     919f( x + y );             g( ®&®(x + y) );
    873920\end{cfa}
    874921Here, the compiler passes the address to the literal 3 or the temporary for the expression ©x + y©, knowing the argument cannot be changed through the parameter.
    875 (The ©&© is necessary for the pointer parameter to make the types match, and is a common requirement for a C programmer.)
    876 \CFA \emph{extends} this semantics to a mutable pointer/reference parameter, and the compiler implicitly creates the necessary temporary (copying the argument), which is subsequently pointed-to by the reference parameter and can be changed.
    877 \begin{cfa}
    878 void f( int & rp );
    879 void g( int * pp );
    880 f( 3 );                   g( &3 );              §\C{// compiler implicit generates temporaries}§
    881 f( x + y );             g( &(x + y) );  §\C{// compiler implicit generates temporaries}§
     922The ©&© before the constant/expression for the pointer-type parameter (©g©) is a \CFA extension necessary to type match and is a common requirement before a variable in C (\eg ©scanf©).
     923Importantly, ©&3© may not be equal to ©&3©, where the references occur across calls because the temporaries maybe different on each call.
     924
     925\CFA \emph{extends} this semantics to a mutable pointer/reference parameter, and the compiler implicitly creates the necessary temporary (copying the argument), which is subsequently pointed-to by the reference parameter and can be changed.\footnote{
     926If whole program analysis is possible, and shows the parameter is not assigned, \ie it is ©const©, the temporary is unnecessary.}
     927\begin{cfa}
     928void f( int & r );
     929void g( int * p );
     930f( 3 );                   g( ®&®3 );            §\C{// compiler implicit generates temporaries}§
     931f( x + y );             g( ®&®(x + y) );        §\C{// compiler implicit generates temporaries}§
    882932\end{cfa}
    883933Essentially, there is an implicit \Index{rvalue} to \Index{lvalue} conversion in this case.\footnote{
     
    885935The implicit conversion allows seamless calls to any routine without having to explicitly name/copy the literal/expression to allow the call.
    886936
    887 While \CFA attempts to handle pointers and references in a uniform, symmetric manner, C handles routine variables in an inconsistent way: a routine variable is both a pointer and a reference (particle and wave).
    888 \begin{cfa}
    889 void f( int p ) {...}
    890 void (*fp)( int ) = &f;                 §\C{// pointer initialization}§
    891 void (*fp)( int ) = f;                  §\C{// reference initialization}§
    892 (*fp)(3);                                               §\C{// pointer invocation}§
    893 fp(3);                                                  §\C{// reference invocation}§
    894 \end{cfa}
    895 A routine variable is best described by a ©const© reference:
    896 \begin{cfa}
    897 const void (&fp)( int ) = f;
    898 fp( 3 );
    899 fp = ...                                                §\C{// error, cannot change code}§
    900 &fp = ...;                                              §\C{// changing routine reference}§
    901 \end{cfa}
    902 because the value of the routine variable is a routine literal, i.e., the routine code is normally immutable during execution.\footnote{
     937%\CFA attempts to handle pointers and references in a uniform, symmetric manner.
     938Finally, C handles \Index{routine object}s in an inconsistent way.
     939A routine object is both a pointer and a reference (\Index{particle and wave}).
     940\begin{cfa}
     941void f( int i );
     942void (*fp)( int );                                      §\C{// routine pointer}§
     943fp = f;                                                         §\C{// reference initialization}§
     944fp = &f;                                                        §\C{// pointer initialization}§
     945fp = *f;                                                        §\C{// reference initialization}§
     946fp(3);                                                          §\C{// reference invocation}§
     947(*fp)(3);                                                       §\C{// pointer invocation}§
     948\end{cfa}
     949While 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.
     950Instead, a routine object should be referenced by a ©const© reference:
     951\begin{cfa}
     952®const® void (®&® fr)( int ) = f;       §\C{// routine reference}§
     953fr = ...                                                        §\C{// error, cannot change code}§
     954&fr = ...;                                                      §\C{// changing routine reference}§
     955fr( 3 );                                                        §\C{// reference call to f}§
     956(*fr)(3);                                                       §\C{// error, incorrect type}§
     957\end{cfa}
     958because the value of the routine object is a routine literal, \ie the routine code is normally immutable during execution.\footnote{
    903959Dynamic code rewriting is possible but only in special circumstances.}
    904 \CFA allows this additional use of references for routine variables in an attempt to give a more consistent meaning for them.
    905 
    906 
    907 \section{Type Operators}
    908 
    909 The new declaration syntax can be used in other contexts where types are required, \eg casts and the pseudo-routine ©sizeof©:
    910 \begin{quote2}
    911 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    912 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    913 \begin{cfa}
    914 y = (®* int®)x;
    915 i = sizeof(®[ 5 ] * int®);
    916 \end{cfa}
    917 &
    918 \begin{cfa}
    919 y = (®int *®)x;
    920 i = sizeof(®int *[ 5 ]®);
    921 \end{cfa}
    922 \end{tabular}
    923 \end{quote2}
     960\CFA allows this additional use of references for routine objects in an attempt to give a more consistent meaning for them.
     961
     962
     963\subsection{Address-of Semantics}
     964
     965In C, ©&E© is an rvalue for any expression ©E©.
     966\CFA extends the ©&© (address-of) operator as follows:
     967\begin{itemize}
     968\item
     969if ©R© is an \Index{rvalue} of type ©T &$_1$...&$_r$© where $r \ge 1$ references (©&© symbols) than ©&R© has type ©T ®*®&$_{\color{red}2}$...&$_{\color{red}r}$©, \ie ©T© pointer with $r-1$ references (©&© symbols).
     970
     971\item
     972if ©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).
     973\end{itemize}
     974The following example shows the first rule applied to different \Index{rvalue} contexts:
     975\begin{cfa}
     976int x, * px, ** ppx, *** pppx, **** ppppx;
     977int & rx = x, && rrx = rx, &&& rrrx = rrx ;
     978x = rrrx;               // rrrx is an lvalue with type int &&& (equivalent to x)
     979px = &rrrx;             // starting from rrrx, &rrrx is an rvalue with type int *&&& (&x)
     980ppx = &&rrrx;   // starting from &rrrx, &&rrrx is an rvalue with type int **&& (&rx)
     981pppx = &&&rrrx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (&rrx)
     982ppppx = &&&&rrrx; // starting from &&&rrrx, &&&&rrrx is an rvalue with type int **** (&rrrx)
     983\end{cfa}
     984The following example shows the second rule applied to different \Index{lvalue} contexts:
     985\begin{cfa}
     986int x, * px, ** ppx, *** pppx;
     987int & rx = x, && rrx = rx, &&& rrrx = rrx ;
     988rrrx = 2;               // rrrx is an lvalue with type int &&& (equivalent to x)
     989&rrrx = px;             // starting from rrrx, &rrrx is an rvalue with type int *&&& (rx)
     990&&rrrx = ppx;   // starting from &rrrx, &&rrrx is an rvalue with type int **&& (rrx)
     991&&&rrrx = pppx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (rrrx)
     992\end{cfa}
     993
     994
     995\subsection{Conversions}
     996
     997C provides a basic implicit conversion to simplify variable usage:
     998\begin{enumerate}
     999\setcounter{enumi}{-1}
     1000\item
     1001lvalue to rvalue conversion: ©cv T© converts to ©T©, which allows implicit variable dereferencing.
     1002\begin{cfa}
     1003int x;
     1004x + 1;                  // lvalue variable (int) converts to rvalue for expression
     1005\end{cfa}
     1006An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped.
     1007\end{enumerate}
     1008\CFA provides three new implicit conversion for reference types to simplify reference usage.
     1009\begin{enumerate}
     1010\item
     1011reference to rvalue conversion: ©cv T &© converts to ©T©, which allows implicit reference dereferencing.
     1012\begin{cfa}
     1013int x, &r = x, f( int p );
     1014x = ®r® + f( ®r® );  // lvalue reference converts to rvalue
     1015\end{cfa}
     1016An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped.
     1017
     1018\item
     1019lvalue to reference conversion: \lstinline[deletekeywords={lvalue}]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
     1020\begin{cfa}
     1021int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &)
     1022f( ®x® );               // lvalue variable (int) convert to reference (int &)
     1023\end{cfa}
     1024Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.
     1025Conversion can expand a type, where ©cv1© $>$ ©cv2©, \eg passing a ©const volatile int© to an ©int &©, which has high cost (\Index{warning});
     1026furthermore, if ©cv1© has ©const© but not ©cv2©, a temporary variable is created to preserve the immutable lvalue.
     1027
     1028\item
     1029rvalue to reference conversion: ©T© converts to ©cv T &©, which allows binding references to temporaries.
     1030\begin{cfa}
     1031int x, & f( int & p );
     1032f( ®x + 3® );   // rvalue parameter (int) implicitly converts to lvalue temporary reference (int &)
     1033®&f®(...) = &x; // rvalue result (int &) implicitly converts to lvalue temporary reference (int &)
     1034\end{cfa}
     1035In both case, modifications to the temporary are inaccessible (\Index{warning}).
     1036Conversion expands the temporary-type with ©cv©, which is low cost since the temporary is inaccessible.
     1037\end{enumerate}
     1038
     1039
     1040\begin{comment}
     1041From: Richard Bilson <rcbilson@gmail.com>
     1042Date: Wed, 13 Jul 2016 01:58:58 +0000
     1043Subject: Re: pointers / references
     1044To: "Peter A. Buhr" <pabuhr@plg2.cs.uwaterloo.ca>
     1045
     1046As a general comment I would say that I found the section confusing, as you move back and forth
     1047between various real and imagined programming languages. If it were me I would rewrite into two
     1048subsections, one that specifies precisely the syntax and semantics of reference variables and
     1049another that provides the rationale.
     1050
     1051I don't see any obvious problems with the syntax or semantics so far as I understand them. It's not
     1052obvious that the description you're giving is complete, but I'm sure you'll find the special cases
     1053as you do the implementation.
     1054
     1055My big gripes are mostly that you're not being as precise as you need to be in your terminology, and
     1056that you say a few things that aren't actually true even though I generally know what you mean.
     1057
     105820 C provides a pointer type; CFA adds a reference type. Both types contain an address, which is normally a
     105921 location in memory.
     1060
     1061An address is not a location in memory; an address refers to a location in memory. Furthermore it
     1062seems weird to me to say that a type "contains" an address; rather, objects of that type do.
     1063
     106421 Special addresses are used to denote certain states or access co-processor memory. By
     106522 convention, no variable is placed at address 0, so addresses like 0, 1, 2, 3 are often used to denote no-value
     106623 or other special states.
     1067
     1068This isn't standard C at all. There has to be one null pointer representation, but it doesn't have
     1069to be a literal zero representation and there doesn't have to be more than one such representation.
     1070
     107123 Often dereferencing a special state causes a memory fault, so checking is necessary
     107224 during execution.
     1073
     1074I don't see the connection between the two clauses here. I feel like if a bad pointer will not cause
     1075a memory fault then I need to do more checking, not less.
     1076
     107724 If the programming language assigns addresses, a program's execution is sound, \ie all
     107825 addresses are to valid memory locations.
     1079
     1080You haven't said what it means to "assign" an address, but if I use my intuitive understanding of
     1081the term I don't see how this can be true unless you're assuming automatic storage management.
     1082
     10831 Program variables are implicit pointers to memory locations generated by the compiler and automatically
     10842 dereferenced, as in:
     1085
     1086There is no reason why a variable needs to have a location in memory, and indeed in a typical
     1087program many variables will not. In standard terminology an object identifier refers to data in the
     1088execution environment, but not necessarily in memory.
     1089
     109013 A pointer/reference is a generalization of a variable name, \ie a mutable address that can point to more
     109114 than one memory location during its lifetime.
     1092
     1093I feel like you're off the reservation here. In my world there are objects of pointer type, which
     1094seem to be what you're describing here, but also pointer values, which can be stored in an object of
     1095pointer type but don't necessarily have to be. For example, how would you describe the value denoted
     1096by "&main" in a C program? I would call it a (function) pointer, but that doesn't satisfy your
     1097definition.
     1098
     109916 not occupy storage as the literal is embedded directly into instructions.) Hence, a pointer occupies memory
     110017 to store its current address, and the pointer's value is loaded by dereferencing, e.g.:
     1101
     1102As with my general objection regarding your definition of variables, there is no reason why a
     1103pointer variable (object of pointer type) needs to occupy memory.
     1104
     110521 p2 = p1 + x; // compiler infers *p2 = *p1 + x;
     1106
     1107What language are we in now?
     1108
     110924 pointer usage. However, in C, the following cases are ambiguous, especially with pointer arithmetic:
     111025 p1 = p2; // p1 = p2 or *p1 = *p2
     1111
     1112This isn't ambiguous. it's defined to be the first option.
     1113
     111426 p1 = p1 + 1; // p1 = p1 + 1 or *p1 = *p1 + 1
     1115
     1116Again, this statement is not ambiguous.
     1117
     111813 example. Hence, a reference behaves like the variable name for the current variable it is pointing-to. The
     111914 simplest way to understand a reference is to imagine the compiler inserting a dereference operator before
     112015 the reference variable for each reference qualifier in a declaration, e.g.:
     1121
     1122It's hard for me to understand who the audience for this part is. I think a practical programmer is
     1123likely to be satisfied with "a reference behaves like the variable name for the current variable it
     1124is pointing-to," maybe with some examples. Your "simplest way" doesn't strike me as simpler than
     1125that. It feels like you're trying to provide a more precise definition for the semantics of
     1126references, but it isn't actually precise enough to be a formal specification. If you want to
     1127express the semantics of references using rewrite rules that's a great way to do it, but lay the
     1128rules out clearly, and when you're showing an example of rewriting keep your
     1129references/pointers/values separate (right now, you use \eg "r3" to mean a reference, a pointer,
     1130and a value).
     1131
     113224 Cancellation works to arbitrary depth, and pointer and reference values are interchangeable because both
     113325 contain addresses.
     1134
     1135Except they're not interchangeable, because they have different and incompatible types.
     1136
     113740 Interestingly, C++ deals with the address duality by making the pointed-to value the default, and prevent-
     113841 ing changes to the reference address, which eliminates half of the duality. Java deals with the address duality
     113942 by making address assignment the default and requiring field assignment (direct or indirect via methods),
     114043 \ie there is no builtin bit-wise or method-wise assignment, which eliminates half of the duality.
     1141
     1142I can follow this but I think that's mostly because I already understand what you're trying to
     1143say. I don't think I've ever heard the term "method-wise assignment" and I don't see you defining
     1144it. Furthermore Java does have value assignment of basic (non-class) types, so your summary here
     1145feels incomplete. (If it were me I'd drop this paragraph rather than try to save it.)
     1146
     114711 Hence, for type & const, there is no pointer assignment, so &rc = &x is disallowed, and the address value
     114812 cannot be 0 unless an arbitrary pointer is assigned to the reference.
     1149
     1150Given the pains you've taken to motivate every little bit of the semantics up until now, this last
     1151clause ("the address value cannot be 0") comes out of the blue. It seems like you could have
     1152perfectly reasonable semantics that allowed the initialization of null references.
     1153
     115412 In effect, the compiler is managing the
     115513 addresses for type & const not the programmer, and by a programming discipline of only using references
     115614 with references, address errors can be prevented.
     1157
     1158Again, is this assuming automatic storage management?
     1159
     116018 rary binding. For reference initialization (like pointer), the initializing value must be an address (lvalue) not
     116119 a value (rvalue).
     1162
     1163This sentence appears to suggest that an address and an lvalue are the same thing.
     1164
     116520 int * p = &x; // both &x and x are possible interpretations
     1166
     1167Are you saying that we should be considering "x" as a possible interpretation of the initializer
     1168"&x"? It seems to me that this expression has only one legitimate interpretation in context.
     1169
     117021 int & r = x; // x unlikely interpretation, because of auto-dereferencing
     1171
     1172You mean, we can initialize a reference using an integer value? Surely we would need some sort of
     1173cast to induce that interpretation, no?
     1174
     117522 Hence, the compiler implicitly inserts a reference operator, &, before the initialization expression.
     1176
     1177But then the expression would have pointer type, which wouldn't be compatible with the type of r.
     1178
     117922 Similarly,
     118023 when a reference is used for a parameter/return type, the call-site argument does not require a reference
     118124 operator.
     1182
     1183Furthermore, it would not be correct to use a reference operator.
     1184
     118545 The implicit conversion allows
     11861 seamless calls to any routine without having to explicitly name/copy the literal/expression to allow the call.
     11872 While C' attempts to handle pointers and references in a uniform, symmetric manner, C handles routine
     11883 variables in an inconsistent way: a routine variable is both a pointer and a reference (particle and wave).
     1189
     1190After all this talk of how expressions can have both pointer and value interpretations, you're
     1191disparaging C because it has expressions that have both pointer and value interpretations?
     1192
     1193On Sat, Jul 9, 2016 at 4:18 PM Peter A. Buhr <pabuhr@plg.uwaterloo.ca> wrote:
     1194> Aaron discovered a few places where "&"s are missing and where there are too many "&", which are
     1195> corrected in the attached updated. None of the text has changed, if you have started reading
     1196> already.
     1197\end{comment}
    9241198
    9251199
    9261200\section{Routine Definition}
    9271201
    928 \CFA also supports a new syntax for routine definition, as well as ISO C and K\&R routine syntax.
     1202\CFA also supports a new syntax for routine definition, as well as \Celeven and K\&R routine syntax.
    9291203The point of the new syntax is to allow returning multiple values from a routine~\cite{Galletly96,CLU}, \eg:
    9301204\begin{cfa}
     
    9461220in 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:
    9471221\begin{cfa}
    948 [§\,§] g();                                             §\C{// no input or output parameters}§
    949 [ void ] g( void );                             §\C{// no input or output parameters}§
     1222[§\,§] g();                                                     §\C{// no input or output parameters}§
     1223[ void ] g( void );                                     §\C{// no input or output parameters}§
    9501224\end{cfa}
    9511225
     
    9651239\begin{cfa}
    9661240typedef int foo;
    967 int f( int (* foo) );                   §\C{// foo is redefined as a parameter name}§
     1241int f( int (* foo) );                           §\C{// foo is redefined as a parameter name}§
    9681242\end{cfa}
    9691243The 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.
     
    9731247C-style declarations can be used to declare parameters for \CFA style routine definitions, \eg:
    9741248\begin{cfa}
    975 [ int ] f( * int, int * );              §\C{// returns an integer, accepts 2 pointers to integers}§
    976 [ * int, int * ] f( int );              §\C{// returns 2 pointers to integers, accepts an integer}§
     1249[ int ] f( * int, int * );                      §\C{// returns an integer, accepts 2 pointers to integers}§
     1250[ * int, int * ] f( int );                      §\C{// returns 2 pointers to integers, accepts an integer}§
    9771251\end{cfa}
    9781252The 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:
    9791253\begin{cfa}
    9801254#define ptoa( n, d ) int (*n)[ d ]
    981 int f( ptoa( p, 5 ) ) ...               §\C{// expands to int f( int (*p)[ 5 ] )}§
    982 [ int ] f( ptoa( p, 5 ) ) ...   §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§
     1255int f( ptoa( p, 5 ) ) ...                       §\C{// expands to int f( int (*p)[ 5 ] )}§
     1256[ int ] f( ptoa( p, 5 ) ) ...           §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§
    9831257\end{cfa}
    9841258Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    10021276        int z;
    10031277        ... x = 0; ... y = z; ...
    1004         ®return;® §\C{// implicitly return x, y}§
     1278        ®return;®                                                       §\C{// implicitly return x, y}§
    10051279}
    10061280\end{cfa}
     
    10121286[ int x, int y ] f() {
    10131287        ...
    1014 } §\C{// implicitly return x, y}§
     1288}                                                                               §\C{// implicitly return x, y}§
    10151289\end{cfa}
    10161290In this case, the current values of ©x© and ©y© are returned to the calling routine just as if a ©return© had been encountered.
     1291
     1292Named return values may be used in conjunction with named parameter values;
     1293specifically, a return and parameter can have the same name.
     1294\begin{cfa}
     1295[ int x, int y ] f( int, x, int y ) {
     1296        ...
     1297}                                                                               §\C{// implicitly return x, y}§
     1298\end{cfa}
     1299This notation allows the compiler to eliminate temporary variables in nested routine calls.
     1300\begin{cfa}
     1301[ int x, int y ] f( int, x, int y );    §\C{// prototype declaration}§
     1302int a, b;
     1303[a, b] = f( f( f( a, b ) ) );
     1304\end{cfa}
     1305While the compiler normally ignores parameters names in prototype declarations, here they are used to eliminate temporary return-values by inferring that the results of each call are the inputs of the next call, and ultimately, the left-hand side of the assignment.
     1306Hence, even without the body of routine ©f© (separate compilation), it is possible to perform a global optimization across routine calls.
     1307The compiler warns about naming inconsistencies between routine prototype and definition in this case, and behaviour is \Index{undefined} if the programmer is inconsistent.
    10171308
    10181309
     
    10221313as well, parameter names are optional, \eg:
    10231314\begin{cfa}
    1024 [ int x ] f ();                                 §\C{// returning int with no parameters}§
    1025 [ * int ] g (int y);                    §\C{// returning pointer to int with int parameter}§
    1026 [ ] h (int,char);                               §\C{// returning no result with int and char parameters}§
    1027 [ * int,int ] j (int);                  §\C{// returning pointer to int and int, with int parameter}§
     1315[ int x ] f ();                                                 §\C{// returning int with no parameters}§
     1316[ * int ] g (int y);                                    §\C{// returning pointer to int with int parameter}§
     1317[ ] h ( int, char );                                    §\C{// returning no result with int and char parameters}§
     1318[ * int, int ] j ( int );                               §\C{// returning pointer to int and int, with int parameter}§
    10281319\end{cfa}
    10291320This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
     
    10331324\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    10341325\begin{cfa}
    1035 [ int ] f(int), g;
     1326[ int ] f( int ), g;
    10361327\end{cfa}
    10371328&
    10381329\begin{cfa}
    1039 int f(int), g(int);
     1330int f( int ), g( int );
    10401331\end{cfa}
    10411332\end{tabular}
     
    10431334Declaration qualifiers can only appear at the start of a \CFA routine declaration,\footref{StorageClassSpecifier} \eg:
    10441335\begin{cfa}
    1045 extern [ int ] f (int);
    1046 static [ int ] g (int);
     1336extern [ int ] f ( int );
     1337static [ int ] g ( int );
    10471338\end{cfa}
    10481339
     
    10521343The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg:
    10531344\begin{cfa}
    1054 * [ int x ] () fp;                      §\C{// pointer to routine returning int with no parameters}§
    1055 * [ * int ] (int y) gp;         §\C{// pointer to routine returning pointer to int with int parameter}§
    1056 * [ ] (int,char) hp;            §\C{// pointer to routine returning no result with int and char parameters}§
    1057 * [ * int,int ] (int) jp;       §\C{// pointer to routine returning pointer to int and int, with int parameter}§
     1345* [ int x ] () fp;                                              §\C{// pointer to routine returning int with no parameters}§
     1346* [ * int ] (int y) gp;                                 §\C{// pointer to routine returning pointer to int with int parameter}§
     1347* [ ] (int,char) hp;                                    §\C{// pointer to routine returning no result with int and char parameters}§
     1348* [ * int,int ] ( int ) jp;                             §\C{// pointer to routine returning pointer to int and int, with int parameter}§
    10581349\end{cfa}
    10591350While parameter names are optional, \emph{a routine name cannot be specified};
    10601351for example, the following is incorrect:
    10611352\begin{cfa}
    1062 * [ int x ] f () fp;            §\C{// routine name "f" is not allowed}§
     1353* [ int x ] f () fp;                                    §\C{// routine name "f" is not allowed}§
    10631354\end{cfa}
    10641355
     
    10661357\section{Named and Default Arguments}
    10671358
    1068 Named and default arguments~\cite{Hardgrave76}\footnote{
     1359Named\index{named arguments}\index{arguments!named} and default\index{default arguments}\index{arguments!default} arguments~\cite{Hardgrave76}\footnote{
    10691360Francez~\cite{Francez77} proposed a further extension to the named-parameter passing style, which specifies what type of communication (by value, by reference, by name) the argument is passed to the routine.}
    10701361are two mechanisms to simplify routine call.
     
    12331524
    12341525Given the \CFA restrictions above, both named and default arguments are backwards compatible.
    1235 \Index*[C++]{\CC} only supports default arguments;
     1526\Index*[C++]{\CC{}} only supports default arguments;
    12361527\Index*{Ada} supports both named and default arguments.
    12371528
    12381529
    1239 \section{Type/Routine Nesting}
     1530\section{Unnamed Structure Fields}
     1531
     1532C requires each field of a structure to have a name, except for a bit field associated with a basic type, \eg:
     1533\begin{cfa}
     1534struct {
     1535        int f1;                                 §\C{// named field}§
     1536        int f2 : 4;                             §\C{// named field with bit field size}§
     1537        int : 3;                                §\C{// unnamed field for basic type with bit field size}§
     1538        int ;                                   §\C{// disallowed, unnamed field}§
     1539        int *;                                  §\C{// disallowed, unnamed field}§
     1540        int (*)( int );                 §\C{// disallowed, unnamed field}§
     1541};
     1542\end{cfa}
     1543This requirement is relaxed by making the field name optional for all field declarations; therefore, all the field declarations in the example are allowed.
     1544As for unnamed bit fields, an unnamed field is used for padding a structure to a particular size.
     1545A list of unnamed fields is also supported, \eg:
     1546\begin{cfa}
     1547struct {
     1548        int , , ;                               §\C{// 3 unnamed fields}§
     1549}
     1550\end{cfa}
     1551
     1552
     1553\section{Nesting}
    12401554
    12411555Nesting of types and routines is useful for controlling name visibility (\newterm{name hiding}).
     
    12441558\subsection{Type Nesting}
    12451559
    1246 \CFA allows \Index{type nesting}, and type qualification of the nested typres (see \VRef[Figure]{f:TypeNestingQualification}), where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
     1560\CFA allows \Index{type nesting}, and type qualification of the nested types (see \VRef[Figure]{f:TypeNestingQualification}), where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
    12471561\begin{figure}
    12481562\centering
     
    13471661}
    13481662int main() {
    1349         * [int](int) fp = foo();        §\C{// int (*fp)(int)}§
    1350     sout | fp( 3 ) | endl;
     1663        * [int]( int ) fp = foo();      §\C{// int (*fp)( int )}§
     1664        sout | fp( 3 ) | endl;
    13511665}
    13521666\end{cfa}
    13531667because
    13541668
    1355 Currently, there are no \Index{lambda} expressions, i.e., unnamed routines because routine names are very important to properly select the correct routine.
    1356 
    1357 
    1358 \section{Lexical List}
     1669Currently, there are no \Index{lambda} expressions, \ie unnamed routines because routine names are very important to properly select the correct routine.
     1670
     1671
     1672\section{Tuples}
    13591673
    13601674In C and \CFA, lists of elements appear in several contexts, such as the parameter list for a routine call.
     
    13731687[ v+w, x*y, 3.14159, f() ]
    13741688\end{cfa}
    1375 Tuples are permitted to contain sub-tuples (i.e., nesting), such as ©[ [ 14, 21 ], 9 ]©, which is a 2-element tuple whose first element is itself a tuple.
     1689Tuples are permitted to contain sub-tuples (\ie nesting), such as ©[ [ 14, 21 ], 9 ]©, which is a 2-element tuple whose first element is itself a tuple.
    13761690Note, a tuple is not a record (structure);
    13771691a record denotes a single value with substructure, whereas a tuple is multiple values with no substructure (see flattening coercion in Section 12.1).
     
    14291743tuple does not have structure like a record; a tuple is simply converted into a list of components.
    14301744\begin{rationale}
    1431 The present implementation of \CFA does not support nested routine calls when the inner routine returns multiple values; i.e., a statement such as ©g( f() )© is not supported.
     1745The present implementation of \CFA does not support nested routine calls when the inner routine returns multiple values; \ie a statement such as ©g( f() )© is not supported.
    14321746Using a temporary variable to store the  results of the inner routine and then passing this variable to the outer routine works, however.
    14331747\end{rationale}
     
    14421756This requirement is the same as for comma expressions in argument lists.
    14431757
    1444 Type qualifiers, i.e., const and volatile, may modify a tuple type.
    1445 The meaning is the same as for a type qualifier modifying an aggregate type [Int99, x 6.5.2.3(7),x 6.7.3(11)], i.e., the qualifier is distributed across all of the types in the tuple, \eg:
     1758Type qualifiers, \ie const and volatile, may modify a tuple type.
     1759The meaning is the same as for a type qualifier modifying an aggregate type [Int99, x 6.5.2.3(7),x 6.7.3(11)], \ie the qualifier is distributed across all of the types in the tuple, \eg:
    14461760\begin{cfa}
    14471761const volatile [ int, float, const int ] x;
     
    14811795©w© is implicitly opened to yield a tuple of four values, which are then assigned individually.
    14821796
    1483 A \newterm{flattening coercion} coerces a nested tuple, i.e., a tuple with one or more components, which are themselves tuples, into a flattened tuple, which is a tuple whose components are not tuples, as in:
     1797A \newterm{flattening coercion} coerces a nested tuple, \ie a tuple with one or more components, which are themselves tuples, into a flattened tuple, which is a tuple whose components are not tuples, as in:
    14841798\begin{cfa}
    14851799[ a, b, c, d ] = [ 1, [ 2, 3 ], 4 ];
     
    15161830\end{cfa}
    15171831\index{lvalue}
    1518 The left-hand side is a tuple of \emph{lvalues}, which is a list of expressions each yielding an address, i.e., any data object that can appear on the left-hand side of a conventional assignment statement.
     1832The left-hand side is a tuple of \emph{lvalues}, which is a list of expressions each yielding an address, \ie any data object that can appear on the left-hand side of a conventional assignment statement.
    15191833©$\emph{expr}$© is any standard arithmetic expression.
    15201834Clearly, the types of the entities being assigned must be type compatible with the value of the expression.
     
    15571871\index{lvalue}
    15581872The left-hand side is a tuple of \emph{lvalues}, and the right-hand side is a tuple of \emph{expr}s.
    1559 Each \emph{expr} appearing on the righthand side of a multiple assignment statement is assigned to the corresponding \emph{lvalues} on the left-hand side of the statement using parallel semantics for each assignment.
     1873Each \emph{expr} appearing on the right-hand side of a multiple assignment statement is assigned to the corresponding \emph{lvalues} on the left-hand side of the statement using parallel semantics for each assignment.
    15601874An example of multiple assignment is:
    15611875\begin{cfa}
     
    16041918[ x1, y1 ] = z = 0;
    16051919\end{cfa}
    1606 As in C, the rightmost assignment is performed first, i.e., assignment parses right to left.
    1607 
    1608 
    1609 \section{Unnamed Structure Fields}
    1610 
    1611 C requires each field of a structure to have a name, except for a bit field associated with a basic type, \eg:
    1612 \begin{cfa}
    1613 struct {
    1614         int f1;                                 §\C{// named field}§
    1615         int f2 : 4;                             §\C{// named field with bit field size}§
    1616         int : 3;                                §\C{// unnamed field for basic type with bit field size}§
    1617         int ;                                   §\C{// disallowed, unnamed field}§
    1618         int *;                                  §\C{// disallowed, unnamed field}§
    1619         int (*)(int);                   §\C{// disallowed, unnamed field}§
    1620 };
    1621 \end{cfa}
    1622 This requirement is relaxed by making the field name optional for all field declarations; therefore, all the field declarations in the example are allowed.
    1623 As for unnamed bit fields, an unnamed field is used for padding a structure to a particular size.
    1624 A list of unnamed fields is also supported, \eg:
    1625 \begin{cfa}
    1626 struct {
    1627         int , , ;                               §\C{// 3 unnamed fields}§
    1628 }
    1629 \end{cfa}
     1920As in C, the rightmost assignment is performed first, \ie assignment parses right to left.
    16301921
    16311922
     
    16691960
    16701961
    1671 \section{Labelled Continue / Break}
     1962\section{Labelled Continue/Break}
    16721963
    16731964While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure.
    1674 Unfortunately, this restriction forces programmers to use ©goto© to achieve the equivalent control-flow for more than one level of nesting.
    1675 To prevent having to switch to the ©goto©, \CFA extends the ©continue©\index{continue@©continue©}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and ©break©\index{break@©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,Java}.
     1965Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
     1966To 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,Java}.
    16761967For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    16771968for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
    1678 
    1679 The following example shows the labelled ©continue© specifying which control structure is the target for the next loop iteration:
    1680 \begin{quote2}
    1681 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    1682 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    1683 \begin{cfa}
    1684 ®L1:® do {
    1685         ®L2:® while ( ... ) {
    1686                 ®L3:® for ( ... ) {
    1687                         ... continue ®L1®; ...  // continue do
    1688                         ... continue ®L2®; ...  // continue while
    1689                         ... continue ®L3®; ...  // continue for
    1690                 } // for
    1691         } // while
    1692 } while ( ... );
    1693 \end{cfa}
    1694 &
    1695 \begin{cfa}
    1696 do {
    1697         while ( ... ) {
    1698                 for ( ... ) {
    1699                         ... goto L1; ...
    1700                         ... goto L2; ...
    1701                         ... goto L3; ...
    1702                 L3: ; }
    1703         L2: ; }
    1704 L1: ; } while ( ... );
    1705 \end{cfa}
    1706 \end{tabular}
    1707 \end{quote2}
    1708 The innermost loop has three restart points, which cause the next loop iteration to begin.
    1709 
    1710 The following example shows the labelled ©break© specifying which control structure is the target for exit:
    1711 \begin{quote2}
    1712 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    1713 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    1714 \begin{cfa}
    1715 ®L1:® {
     1969\VRef[Figure]{f:MultiLevelResumeTermination} shows the labelled ©continue© and ©break©, specifying which control structure is the target for exit, and the corresponding C program using only ©goto©.
     1970The innermost loop has 7 exit points, which cause resumption or termination of one or more of the 7 \Index{nested control-structure}s.
     1971
     1972\begin{figure}
     1973\begin{tabular}{@{\hspace{\parindentlnth}}l@{\hspace{1.5em}}l@{}}
     1974\multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{\CFA}}      & \multicolumn{1}{c}{\textbf{C}}        \\
     1975\begin{cfa}
     1976®LC:® {
    17161977        ... §declarations§ ...
    1717         ®L2:® switch ( ... ) {
     1978        ®LS:® switch ( ... ) {
    17181979          case 3:
    1719             ®L3:® if ( ... ) {
    1720                         ®L4:® for ( ... ) {
    1721                                 ... break ®L1®; ...     // exit compound statement
    1722                                 ... break ®L2®; ...     // exit switch
    1723                                 ... break ®L3®; ...     // exit if
    1724                                 ... break ®L4®; ...     // exit loop
     1980                ®LIF:® if ( ... ) {
     1981                        ®LF:® for ( ... ) {
     1982                                ®LW:® while ( ... ) {
     1983                                        ... break ®LC®; ...                     // terminate compound
     1984                                        ... break ®LS®; ...                     // terminate switch
     1985                                        ... break ®LIF®; ...                    // terminate if
     1986                                        ... continue ®LF;® ...   // resume loop
     1987                                        ... break ®LF®; ...                     // terminate loop
     1988                                        ... continue ®LW®; ...   // resume loop
     1989                                        ... break ®LW®; ...               // terminate loop
     1990                                } // while
    17251991                        } // for
    17261992                } else {
    1727                         ... break ®L3®; ...             // exit if
     1993                        ... break ®LIF®; ...                                     // terminate if
    17281994                } // if
    17291995        } // switch
     
    17362002        switch ( ... ) {
    17372003          case 3:
    1738             if ( ... ) {
     2004                if ( ... ) {
    17392005                        for ( ... ) {
    1740                                 ... goto L1; ...
    1741                                 ... goto L2; ...
    1742                                 ... goto L3; ...
    1743                                 ... goto L4; ...
    1744                         } L4: ;
     2006                                while ( ... ) {
     2007                                        ... goto ®LC®; ...
     2008                                        ... goto ®LS®; ...
     2009                                        ... goto ®LIF®; ...
     2010                                        ... goto ®LFC®; ...
     2011                                        ... goto ®LFB®; ...
     2012                                        ... goto ®LWC®; ...
     2013                                        ... goto ®LWB®; ...
     2014                                  ®LWC®: ; } ®LWB:® ;
     2015                          ®LFC:® ; } ®LFB:® ;
    17452016                } else {
    1746                         ... goto L3; ...
    1747                 } L3: ;
    1748         } L2: ;
    1749 } L1: ;
     2017                        ... goto ®LIF®; ...
     2018                } ®L3:® ;
     2019        } ®LS:® ;
     2020} ®LC:® ;
    17502021\end{cfa}
    17512022\end{tabular}
    1752 \end{quote2}
    1753 The innermost loop has four exit points, which cause termination of one or more of the four \Index{nested control structure}s.
    1754 
    1755 Both ©continue© and ©break© with target labels are simply a ©goto©\index{goto@©goto©!restricted} restricted in the following ways:
     2023\caption{Multi-level Resume/Termination}
     2024\label{f:MultiLevelResumeTermination}
     2025\end{figure}
     2026
     2027\begin{comment}
     2028int main() {
     2029  LC: {
     2030          LS: switch ( 1 ) {
     2031                  case 3:
     2032                  LIF: if ( 1 ) {
     2033                          LF: for ( ;; ) {
     2034                                  LW: while ( 1 ) {
     2035                                                break LC;                       // terminate compound
     2036                                                break LS;                       // terminate switch
     2037                                                break LIF;                      // terminate if
     2038                                                continue LF;     // resume loop
     2039                                                break LF;                       // terminate loop
     2040                                                continue LW;     // resume loop
     2041                                                break LW;                 // terminate loop
     2042                                        } // while
     2043                                } // for
     2044                        } else {
     2045                                break LIF;                                       // terminate if
     2046                        } // if
     2047                } // switch
     2048        } // compound
     2049        {
     2050                switch ( 1 ) {
     2051                  case 3:
     2052                        if ( 1 ) {
     2053                                for ( ;; ) {
     2054                                        while ( 1 ) {
     2055                                                goto LCx;
     2056                                                goto LSx;
     2057                                                goto LIF;
     2058                                                goto LFC;
     2059                                                goto LFB;
     2060                                                goto LWC;
     2061                                                goto LWB;
     2062                                          LWC: ; } LWB: ;
     2063                                  LFC: ; } LFB: ;
     2064                        } else {
     2065                                goto LIF;
     2066                        } L3: ;
     2067                } LSx: ;
     2068        } LCx: ;
     2069}
     2070
     2071// Local Variables: //
     2072// tab-width: 4 //
     2073// End: //
     2074\end{comment}
     2075
     2076
     2077Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline $goto$!restricted} restricted in the following ways:
    17562078\begin{itemize}
    17572079\item
    1758 They cannot be used to create a loop.
    1759 This means that only the looping construct can be used to create a loop.
    1760 This restriction is important since all situations that can result in repeated execution of statements in a program are clearly delineated.
    1761 \item
    1762 Since they always transfer out of containing control structures, they cannot be used to branch into a control structure.
     2080They cannot create a loop, which means only the looping constructs cause looping.
     2081This restriction means all situations resulting in repeated execution are clearly delineated.
     2082\item
     2083They cannot branch into a control structure.
     2084This restriction prevents missing initialization at the start of a control structure resulting in undefined behaviour.
    17632085\end{itemize}
    1764 The advantage of the labelled ©continue©/©break© is allowing static multi-level exits without having to use the ©goto© statement and tying control flow to the target control structure rather than an arbitrary point in a program.
     2086The advantage of the labelled ©continue©/©break© is allowing static multi-level exits without having to use the ©goto© statement, and tying control flow to the target control structure rather than an arbitrary point in a program.
    17652087Furthermore, the location of the label at the \emph{beginning} of the target control structure informs the reader that complex control-flow is occurring in the body of the control structure.
    17662088With ©goto©, the label is at the end of the control structure, which fails to convey this important clue early enough to the reader.
    17672089Finally, using an explicit target for the transfer instead of an implicit target allows new constructs to be added or removed without affecting existing constructs.
    1768 The implicit targets of the current ©continue© and ©break©, i.e., the closest enclosing loop or ©switch©, change as certain constructs are added or removed.
     2090The implicit targets of the current ©continue© and ©break©, \ie the closest enclosing loop or ©switch©, change as certain constructs are added or removed.
    17692091
    17702092
     
    19032225Furthermore, 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.
    19042226As 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.
    1905 The key observation is that the ©switch© statement branches into control structure, i.e., there are multiple entry points into its statement body.
     2227The key observation is that the ©switch© statement branches into control structure, \ie there are multiple entry points into its statement body.
    19062228\end{enumerate}
    19072229
     
    19112233the number of ©switch© statements is small,
    19122234\item
    1913 most ©switch© statements are well formed (i.e., no \Index*{Duff's device}),
     2235most ©switch© statements are well formed (\ie no \Index*{Duff's device}),
    19142236\item
    19152237the ©default© clause is usually written as the last case-clause,
     
    19212243\item
    19222244Eliminating default fall-through has the greatest potential for affecting existing code.
    1923 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, i.e., a list of ©case© clauses executing common code, \eg:
     2245However, 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:
    19242246\begin{cfa}
    19252247case 1:  case 2:  case 3: ...
     
    19642286        ®int j = 0;®                            §\C{// disallowed}§
    19652287  case 1:
    1966     {
     2288        {
    19672289                ®int k = 0;®                    §\C{// allowed at different nesting levels}§
    19682290                ...
     
    20792401\index{input/output library}
    20802402
    2081 The goal for the \CFA I/O is to make I/O as simple as possible in the common cases, while fully supporting polymorphism and user defined types in a consistent way.
     2403The 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.
     2404The \CFA header file for the I/O library is \Indexc{fstream}.
     2405
    20822406The common case is printing out a sequence of variables separated by whitespace.
    20832407\begin{quote2}
     
    20852409\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
    20862410\begin{cfa}
    2087 int x = 0, y = 1, z = 2;
     2411int x = 1, y = 2, z = 3;
    20882412sout | x ®|® y ®|® z | endl;
    20892413\end{cfa}
     
    20922416
    20932417cout << x ®<< " "® << y ®<< " "® << z << endl;
     2418\end{cfa}
     2419\\
     2420\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     24211 2 3
     2422\end{cfa}
     2423&
     2424\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     24251 2 3
    20942426\end{cfa}
    20952427\end{tabular}
    20962428\end{quote2}
    20972429The \CFA form has half as many characters as the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators.
    2098 
    2099 The logical-or operator is used because it is the lowest-priority overloadable operator, other than assignment.
     2430A tuple prints all the tuple's values, each separated by ©", "©.
     2431\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2432[int, int] t1 = [1, 2], t2 = [3, 4];
     2433sout | t1 | t2 | endl;                                  §\C{// print tuples}§
     2434\end{cfa}
     2435\begin{cfa}[mathescape=off,showspaces=true,belowskip=0pt]
     24361, 2, 3, 4
     2437\end{cfa}
     2438\CFA uses the logical-or operator for I/O because it is the lowest-priority overloadable operator, other than assignment.
    21002439Therefore, fewer output expressions require parenthesis.
    21012440\begin{quote2}
     
    21102449&
    21112450\begin{cfa}
    2112 cout << x * 3 << y + 1 << (z << 2) << (x == y) << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
     2451cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
     2452\end{cfa}
     2453\\
     2454&
     2455\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     24563 3 12 0 3 1 2
    21132457\end{cfa}
    21142458\end{tabular}
     
    21162460Finally, the logical-or operator has a link with the Shell pipe-operator for moving data, where data flows in the correct direction for input but the opposite direction for output.
    21172461
    2118 The implicit separator\index{I/O separator} character (space/blank) is a separator not a terminator.
     2462
     2463The implicit separator\index{I/O!separator} character (space/blank) is a separator not a terminator.
    21192464The rules for implicitly adding the separator are:
    21202465\begin{enumerate}
     
    212724721 2 3
    21282473\end{cfa}
     2474
    21292475\item
    21302476A separator does not appear before or after a character literal or variable.
     
    21332479123
    21342480\end{cfa}
    2135 \item
    2136 A separator does not appear before or after a null (empty) C string
     2481
     2482\item
     2483A separator does not appear before or after a null (empty) C string.
    21372484\begin{cfa}
    21382485sout | 1 | "" | 2 | "" | 3 | endl;
     
    21402487\end{cfa}
    21412488which is a local mechanism to disable insertion of the separator character.
    2142 \item
    2143 A separator does not appear before a C string starting with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off]@([{=$£¥¡¿«@
     2489
     2490\item
     2491A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$£¥¡¿«@
    21442492%$
    21452493\begin{cfa}[mathescape=off]
     
    21482496\end{cfa}
    21492497%$
    2150 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    2151 x (1 x [2 x {3 x =4 x $5 x £6 x ¥7 x ¡8 x ¿9 x «10
     2498\begin{cfa}[mathescape=off,basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
     2499x ®(®1 x ®[®2 x ®{®3 x ®=®4 x ®$®5 x ®£®6 x ®¥®7 x ®¡®8 x ®¿®9 x ®«®10
    21522500\end{cfa}
    21532501%$
     2502where \lstinline[basicstyle=\tt]@¡¿@ are inverted opening exclamation and question marks, and \lstinline[basicstyle=\tt]@«@ is an opening citation mark.
     2503
    21542504\item
    21552505{\lstset{language=CFA,deletedelim=**[is][]{¢}{¢}}
    2156 A seperator does not appear after a C string ending with the (extended) \Index{ASCII}\index{ASCII!extended} characters: ©,.;!?)]}%¢»©
     2506A seperator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[basicstyle=\tt]@,.;!?)]}%¢»@
    21572507\begin{cfa}[belowskip=0pt]
    21582508sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    21592509                | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;
    21602510\end{cfa}
    2161 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    2162 1, x 2. x 3; x 4! x 5? x 6% x 7§\textcent§ x 8» x 9) x 10] x 11} x
     2511\begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
     25121®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7§\color{red}\textcent§ x 8®»® x 9®)® x 10®]® x 11®}® x
    21632513\end{cfa}}%
    2164 \item
    2165 A seperator does not appear before or after a C string begining/ending with the \Index{ASCII} quote or whitespace characters: \lstinline[showspaces=true]@`'": \t\v\f\r\n@
     2514where \lstinline[basicstyle=\tt]@»@ is a closing citation mark.
     2515
     2516\item
     2517A 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@
    21662518\begin{cfa}[belowskip=0pt]
    21672519sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;
    21682520\end{cfa}
    2169 \begin{cfa}[mathescape=off,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
    2170 x`1`x'2'x"3"x:4:x 5 x   6       x
     2521\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     2522x®`®1®`®x§\color{red}\texttt{'}§2§\color{red}\texttt{'}§x§\color{red}\texttt{"}§3§\color{red}\texttt{"}§x®:®4®:®x® ®5® ®x®      ®6®     ®x
     2523\end{cfa}
     2524
     2525\item
     2526If a space is desired before or after one of the special string start/end characters, simply insert a space.
     2527\begin{cfa}[belowskip=0pt]
     2528sout | "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;
     2529\end{cfa}
     2530\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     2531x (® ®1® ®) x 2® ®, x 3® ®:x:® ®4
    21712532\end{cfa}
    21722533\end{enumerate}
    21732534
    2174 The following \CC-style \Index{manipulator}s allow control over implicit seperation.
    2175 Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, i.e., the seperator is adjusted only with respect to the next printed item.
     2535The following routines and \CC-style \Index{manipulator}s control implicit seperation.
     2536\begin{enumerate}
     2537\item
     2538Routines \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string.
     2539The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
     2540\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2541sepSet( sout, ", $" );                                          §\C{// set separator from " " to ", \$"}§
     2542sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
     2543\end{cfa}
     2544%$
     2545\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
     25461, $2, $3 ®", $"®
     2547\end{cfa}
     2548%$
     2549\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2550sepSet( sout, " " );                                            §\C{// reset separator to " "}§
     2551sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
     2552\end{cfa}
     2553\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
     25541 2 3 ®" "®
     2555\end{cfa}
     2556
     2557\item
     2558Manipulators \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.
    21762559\begin{cfa}[mathescape=off,belowskip=0pt]
    21772560sout | sepOn | 1 | 2 | 3 | sepOn | endl;        §\C{// separator at start of line}§
     
    2186256912 3
    21872570\end{cfa}
    2188 Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, i.e., the seperator is adjusted with respect to all subsequent printed items, unless locally adjusted.
     2571
     2572\item
     2573Manipulators \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, unless locally adjusted.
    21892574\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    21902575sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// globally turn off implicit separation}§
     
    220525901 2 3
    22062591\end{cfa}
    2207 Printing a tuple outputs all the tuple's values separated by ©", "©:
     2592
     2593\item
     2594Routine \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string.
     2595The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    22082596\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    2209 sout | [2, 3] | [4, 5] | endl;                          §\C{// print tuple}§
     2597sepSetTuple( sout, " " );                                       §\C{// set tuple separator from ", " to " "}§
     2598sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
     2599\end{cfa}
     2600\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
     26011 2 3 4 ®" "®
     2602\end{cfa}
     2603\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2604sepSetTuple( sout, ", " );                                      §\C{// reset tuple separator to ", "}§
     2605sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
     2606\end{cfa}
     2607\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
     26081, 2, 3, 4 ®", "®
     2609\end{cfa}
     2610
     2611\item
     2612The tuple separator can also be turned on and off.
     2613\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2614sout | sepOn | t1 | sepOff | t2 | endl;         §\C{// locally turn on/off implicit separation}§
    22102615\end{cfa}
    22112616\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    2212 2, 3, 4, 5
    2213 \end{cfa}
    2214 The tuple separator can also be turned on and off:
    2215 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    2216 sout | sepOn | [2, 3] | sepOff | [4, 5] | endl; §\C{// locally turn on/off implicit separation}§
    2217 \end{cfa}
    2218 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    2219 , 2, 34, 5
     2617, 1, 23, 4
    22202618\end{cfa}
    22212619Notice a tuple seperator starts the line because the next item is a tuple.
    2222 Finally, the stream routines \Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} and \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} get and set the basic separator-string.
    2223 \begin{cfa}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt]
    2224 sepSet( sout, ", $" );                                          §\C{// set separator from " " to ", \$"}§
    2225 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
    2226 \end{cfa}
    2227 %$
    2228 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    2229 1, $2, $3 ", $"
    2230 \end{cfa}
    2231 %$
    2232 \begin{cfa}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt]
    2233 sepSet( sout, " " );                                            §\C{// reset separator to " "}§
    2234 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
    2235 \end{cfa}
    2236 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    2237 1 2 3 " "
    2238 \end{cfa}
    2239 and the stream routines \Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} and \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} get and set the tuple separator-string.
    2240 \begin{cfa}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt]
    2241 sepSetTuple( sout, " " );                                       §\C{// set tuple separator from ", " to " "}§
    2242 sout | [2, 3] | [4, 5] | " \"" | sepGetTuple( sout ) | "\"" | endl;
    2243 \end{cfa}
    2244 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    2245 2 3 4 5 " "
    2246 \end{cfa}
    2247 \begin{cfa}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt]
    2248 sepSetTuple( sout, ", " );                                      §\C{// reset tuple separator to ", "}§
    2249 sout | [2, 3] | [4, 5] | " \"" | sepGetTuple( sout ) | "\"" | endl;
    2250 \end{cfa}
    2251 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    2252 2, 3, 4, 5 ", "
    2253 \end{cfa}
     2620\end{enumerate}
    22542621
    22552622\begin{comment}
     
    22572624
    22582625int main( void ) {
    2259         int x = 0, y = 1, z = 2;
    2260         sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl | endl;
     2626        int x = 1, y = 2, z = 3;
     2627        sout | x | y | z | endl;
     2628        [int, int] t1 = [1, 2], t2 = [3, 4];
     2629        sout | t1 | t2 | endl;                                          // print tuple
     2630        sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
    22612631        sout | 1 | 2 | 3 | endl;
    22622632        sout | '1' | '2' | '3' | endl;
     
    22672637                | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;
    22682638        sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;
    2269 
    2270         sout | sepOn | 1 | 2 | 3 | sepOn | endl;        // separator at start of line
    2271         sout | 1 | sepOff | 2 | 3 | endl;                       // locally turn off implicit separator
    2272         sout | sepDisable | 1 | 2 | 3 | endl;           // globally turn off implicit separation
    2273         sout | 1 | sepOn | 2 | 3 | endl;                        // locally turn on implicit separator
    2274         sout | sepEnable | 1 | 2 | 3 | endl;            // globally turn on implicit separation
    2275 
    2276         sout | [2, 3] | [4, 5] | endl;                          // print tuple
    2277         sout | sepOn | [2, 3] | sepOff | [4, 5] | endl; // locally turn on/off implicit separation
     2639        sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;
    22782640
    22792641        sepSet( sout, ", $" );                                          // set separator from " " to ", $"
     
    22822644        sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
    22832645
     2646        sout | sepOn | 1 | 2 | 3 | sepOn | endl;        // separator at start of line
     2647        sout | 1 | sepOff | 2 | 3 | endl;                       // locally turn off implicit separator
     2648
     2649        sout | sepDisable | 1 | 2 | 3 | endl;           // globally turn off implicit separation
     2650        sout | 1 | sepOn | 2 | 3 | endl;                        // locally turn on implicit separator
     2651        sout | sepEnable | 1 | 2 | 3 | endl;            // globally turn on implicit separation
     2652
    22842653        sepSetTuple( sout, " " );                                       // set tuple separator from ", " to " "
    2285         sout | [2, 3] | [4, 5] | " \"" | sepGetTuple( sout ) | "\"" | endl;
     2654        sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
    22862655        sepSetTuple( sout, ", " );                                      // reset tuple separator to ", "
    2287         sout | [2, 3] | [4, 5] | " \"" | sepGetTuple( sout ) | "\"" | endl;
     2656        sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
     2657
     2658        sout | t1 | t2 | endl;                                          // print tuple
     2659        sout | sepOn | t1 | sepOff | t2 | endl;         // locally turn on/off implicit separation
    22882660}
    22892661
    22902662// Local Variables: //
    22912663// tab-width: 4 //
     2664// fill-column: 100 //
    22922665// End: //
    22932666\end{comment}
     
    24092782
    24102783
    2411 \subsection{Constructors and Destructors}
     2784\section{Constructors and Destructors}
    24122785
    24132786\CFA supports C initialization of structures, but it also adds constructors for more advanced initialization.
    2414 Additionally, \CFA adds destructors that are called when a variable is de-allocated (variable goes out of scope or object is deleted).
     2787Additionally, \CFA adds destructors that are called when a variable is deallocated (variable goes out of scope or object is deleted).
    24152788These functions take a reference to the structure as a parameter (see References for more information).
    24162789
     
    24612834\caption{Constructors and Destructors}
    24622835\end{figure}
    2463 
    2464 
    2465 \begin{comment}
    2466 \section{References}
    2467 
    2468 
    2469 By introducing references in parameter types, users are given an easy way to pass a value by reference, without the need for NULL pointer checks.
    2470 In structures, a reference can replace a pointer to an object that should always have a valid value.
    2471 When a structure contains a reference, all of its constructors must initialize the reference and all instances of this structure must initialize it upon definition.
    2472 
    2473 The syntax for using references in \CFA is the same as \CC with the exception of reference initialization.
    2474 Use ©&© to specify a reference, and access references just like regular objects, not like pointers (use dot notation to access fields).
    2475 When initializing a reference, \CFA uses a different syntax which differentiates reference initialization from assignment to a reference.
    2476 The ©&© is used on both sides of the expression to clarify that the address of the reference is being set to the address of the variable to which it refers.
    2477 \end{comment}
    24782836
    24792837
     
    27553113
    27563114
     3115\begin{comment}
    27573116\section{Generics}
    27583117
     
    27603119Generics allow programmers to use type variables in place of concrete types so that the code can be reused with multiple types.
    27613120The type parameters can be restricted to satisfy a set of constraints.
    2762 This enables \CFA to build fully compiled generic functions and types, unlike other languages like \Index*[C++]{\CC} where templates are expanded or must be explicitly instantiated.
     3121This enables \CFA to build fully compiled generic functions and types, unlike other languages like \Index*[C++]{\CC{}} where templates are expanded or must be explicitly instantiated.
    27633122
    27643123
    27653124\subsection{Generic Functions}
    27663125
    2767 Generic functions in \CFA are similar to template functions in \Index*[C++]{\CC}, and will sometimes be expanded into specialized versions, just like in \CC.
     3126Generic functions in \CFA are similar to template functions in \Index*[C++]{\CC{}}, and will sometimes be expanded into specialized versions, just like in \CC.
    27683127The difference, however, is that generic functions in \CFA can also be separately compiled, using function pointers for callers to pass in all needed functionality for the given type.
    27693128This means that compiled libraries can contain generic functions that can be used by programs linked with them (statically or dynamically).
     
    27983157generic (type T | bool ?<?(T, T) )
    27993158
    2800 T min(T a, T b) {
     3159T min( T a, T b ) {
    28013160        return a < b ? a : b;
    28023161}
     
    28373196
    28383197generic (type T | Orderable(T))
    2839 T min(T a, T b) {
     3198T min( T a, T b ) {
    28403199        return a < b ? a : b;
    28413200}
     
    28843243
    28853244Generic types are defined using the same mechanisms as those described above for generic functions.
    2886 This feature allows users to create types that have one or more fields that use generic parameters as types, similar to a template classes in \Index*[C++]{\CC}.
     3245This feature allows users to create types that have one or more fields that use generic parameters as types, similar to a template classes in \Index*[C++]{\CC{}}.
    28873246For example, to make a generic linked list, a placeholder is created for the type of the elements, so that the specific type of the elements in the list need not be specified when defining the list.
    28883247In C, something like this would have to be done using void pointers and unsafe casting.
     
    29363295Throwing an exception terminates execution of the current block, invokes the destructors of variables that are local to the block, and propagates the exception to the parent block.
    29373296The exception is immediately re-thrown from the parent block unless it is caught as described below.
    2938 \CFA uses keywords similar to \Index*[C++]{\CC} for exception handling.
     3297\CFA uses keywords similar to \Index*[C++]{\CC{}} for exception handling.
    29393298An exception is thrown using a throw statement, which accepts one argument.
    29403299
     
    29613320        }
    29623321\end{cfa}
     3322\end{comment}
    29633323
    29643324
     
    30203380        Complex *p3 = new(0.5, 1.0); // allocate + 2 param constructor
    30213381}
    3022 
    30233382\end{cfa}
    30243383
     
    30323391
    30333392
     3393\begin{comment}
    30343394\subsection{Unsafe C Constructs}
    30353395
     
    30423402The exact set of unsafe C constructs that will be disallowed in \CFA has not yet been decided, but is sure to include pointer arithmetic, pointer casting, etc.
    30433403Once the full set is decided, the rules will be listed here.
     3404\end{comment}
    30443405
    30453406
    30463407\section{Concurrency}
    3047 
    3048 Today's processors for nearly all use cases, ranging from embedded systems to large cloud computing servers, are composed of multiple cores, often heterogeneous.
    3049 As machines grow in complexity, it becomes more difficult for a program to make the most use of the hardware available.
    3050 \CFA includes built-in concurrency features to enable high performance and improve programmer productivity on these multi-/many-core machines.
    30513408
    30523409Concurrency support in \CFA is implemented on top of a highly efficient runtime system of light-weight, M:N, user level threads.
     
    30553412This enables a very familiar interface to all programmers, even those with no parallel programming experience.
    30563413It also allows the compiler to do static type checking of all communication, a very important safety feature.
    3057 This controlled communication with type safety has some similarities with channels in \Index*{Go}, and can actually implement
    3058 channels exactly, as well as create additional communication patterns that channels cannot.
     3414This controlled communication with type safety has some similarities with channels in \Index*{Go}, and can actually implement channels exactly, as well as create additional communication patterns that channels cannot.
    30593415Mutex objects, monitors, are used to contain mutual exclusion within an object and synchronization across concurrent threads.
    30603416
    3061 Three new keywords are added to support these features:
    3062 
    3063 monitor creates a structure with implicit locking when accessing fields
    3064 
    3065 mutex implies use of a monitor requiring the implicit locking
    3066 
    3067 task creates a type with implicit locking, separate stack, and a thread
     3417\begin{figure}
     3418\begin{cfa}
     3419#include <fstream>
     3420#include <coroutine>
     3421
     3422coroutine Fibonacci {
     3423        int fn;                                                         §\C{// used for communication}§
     3424};
     3425void ?{}( Fibonacci * this ) {
     3426        this->fn = 0;
     3427}
     3428void main( Fibonacci * this ) {
     3429        int fn1, fn2;                                           §\C{// retained between resumes}§
     3430        this->fn = 0;                                           §\C{// case 0}§
     3431        fn1 = this->fn;
     3432        suspend();                                                      §\C{// return to last resume}§
     3433
     3434        this->fn = 1;                                           §\C{// case 1}§
     3435        fn2 = fn1;
     3436        fn1 = this->fn;
     3437        suspend();                                                      §\C{// return to last resume}§
     3438
     3439        for ( ;; ) {                                            §\C{// general case}§
     3440                this->fn = fn1 + fn2;
     3441                fn2 = fn1;
     3442                fn1 = this->fn;
     3443                suspend();                                              §\C{// return to last resume}§
     3444        } // for
     3445}
     3446int next( Fibonacci * this ) {
     3447        resume( this );                                         §\C{// transfer to last suspend}§
     3448        return this->fn;
     3449}
     3450int main() {
     3451        Fibonacci f1, f2;
     3452        for ( int i = 1; i <= 10; i += 1 ) {
     3453                sout | next( &f1 ) | ' ' | next( &f2 ) | endl;
     3454        } // for
     3455}
     3456\end{cfa}
     3457\caption{Fibonacci Coroutine}
     3458\label{f:FibonacciCoroutine}
     3459\end{figure}
     3460
     3461
     3462\subsection{Coroutine}
     3463
     3464\Index{Coroutines} are the precursor to tasks.
     3465\VRef[Figure]{f:FibonacciCoroutine} shows a coroutine that computes the \Index*{Fibonacci} numbers.
    30683466
    30693467
     
    30803478\end{cfa}
    30813479
     3480\begin{figure}
     3481\begin{cfa}
     3482#include <fstream>
     3483#include <kernel>
     3484#include <monitor>
     3485#include <thread>
     3486
     3487monitor global_t {
     3488        int value;
     3489};
     3490
     3491void ?{}(global_t * this) {
     3492        this->value = 0;
     3493}
     3494
     3495static global_t global;
     3496
     3497void increment3( global_t * mutex this ) {
     3498        this->value += 1;
     3499}
     3500void increment2( global_t * mutex this ) {
     3501        increment3( this );
     3502}
     3503void increment( global_t * mutex this ) {
     3504        increment2( this );
     3505}
     3506
     3507thread MyThread {};
     3508
     3509void main( MyThread* this ) {
     3510        for(int i = 0; i < 1_000_000; i++) {
     3511                increment( &global );
     3512        }
     3513}
     3514int main(int argc, char* argv[]) {
     3515        processor p;
     3516        {
     3517                MyThread f[4];
     3518        }
     3519        sout | global.value | endl;
     3520}
     3521\end{cfa}
     3522\caption{Atomic-Counter Monitor}
     3523\caption{f:AtomicCounterMonitor}
     3524\end{figure}
     3525
     3526\begin{comment}
    30823527Since a monitor structure includes an implicit locking mechanism, it does not make sense to copy a monitor;
    30833528it is always passed by reference.
     
    31263571}
    31273572\end{cfa}
     3573\end{comment}
    31283574
    31293575
     
    31333579A task provides mutual exclusion like a monitor, and also has its own execution state and a thread of control.
    31343580Similar to a monitor, a task is defined like a structure:
     3581
     3582\begin{figure}
     3583\begin{cfa}
     3584#include <fstream>
     3585#include <kernel>
     3586#include <stdlib>
     3587#include <thread>
     3588
     3589thread First  { signal_once * lock; };
     3590thread Second { signal_once * lock; };
     3591
     3592void ?{}( First * this, signal_once* lock ) { this->lock = lock; }
     3593void ?{}( Second * this, signal_once* lock ) { this->lock = lock; }
     3594
     3595void main( First * this ) {
     3596        for ( int i = 0; i < 10; i += 1 ) {
     3597                sout | "First : Suspend No." | i + 1 | endl;
     3598                yield();
     3599        }
     3600        signal( this->lock );
     3601}
     3602
     3603void main( Second * this ) {
     3604        wait( this->lock );
     3605        for ( int i = 0; i < 10; i += 1 ) {
     3606                sout | "Second : Suspend No." | i + 1 | endl;
     3607                yield();
     3608        }
     3609}
     3610
     3611int main( void ) {
     3612        signal_once lock;
     3613        sout | "User main begin" | endl;
     3614        {
     3615                processor p;
     3616                {
     3617                        First  f = { &lock };
     3618                        Second s = { &lock };
     3619                }
     3620        }
     3621        sout | "User main end" | endl;
     3622}
     3623\end{cfa}
     3624\caption{Simple Tasks}
     3625\label{f:SimpleTasks}
     3626\end{figure}
     3627
     3628
     3629\begin{comment}
    31353630\begin{cfa}
    31363631type Adder = task {
     
    31423637
    31433638A task may define a constructor, which will be called upon allocation and run on the caller.s thread.
    3144 A destructor may also be defined, which is called at de-allocation (when a dynamic object is deleted or when a local object goes out of scope).
     3639A destructor may also be defined, which is called at deallocation (when a dynamic object is deleted or when a local object goes out of scope).
    31453640After a task is allocated and initialized, its thread is spawned implicitly and begins executing in its function call method.
    31463641All tasks must define this function call method, with a void return value and no additional parameters, or the compiler will report an error.
     
    31863681\end{cfa}
    31873682
    3188 
    31893683\subsection{Cooperative Scheduling}
    31903684
     
    32993793}
    33003794\end{cfa}
    3301 
    3302 
     3795\end{comment}
     3796
     3797
     3798\begin{comment}
    33033799\section{Modules and Packages }
    33043800
    3305 \begin{comment}
    33063801High-level encapsulation is useful for organizing code into reusable units, and accelerating compilation speed.
    33073802\CFA provides a convenient mechanism for creating, building and sharing groups of functionality that enhances productivity and improves compile time.
     
    33193814\subsection{No Declarations, No Header Files}
    33203815
    3321 In C and \Index*[C++]{\CC}, it is necessary to declare or define every global variable, global function, and type before it is used in each file.
     3816In C and \Index*[C++]{\CC{}}, it is necessary to declare or define every global variable, global function, and type before it is used in each file.
    33223817Header files and a preprocessor are normally used to avoid repeating code.
    33233818Thus, many variables, functions, and types are described twice, which exposes an opportunity for errors and causes additional maintenance work.
     
    39644459In developing \CFA, many other languages were consulted for ideas, constructs, and syntax.
    39654460Therefore, it is important to show how these languages each compare with Do.
    3966 In this section, \CFA is compared with what the writers of this document consider to be the closest competitors of Do: \Index*[C++]{\CC}, \Index*{Go}, \Index*{Rust}, and \Index*{D}.
    3967 
    3968 
     4461In this section, \CFA is compared with what the writers of this document consider to be the closest competitors of Do: \Index*[C++]{\CC{}}, \Index*{Go}, \Index*{Rust}, and \Index*{D}.
     4462
     4463
     4464\begin{comment}
    39694465\subsection[Comparing Key Features of CFA]{Comparing Key Features of \CFA}
    39704466
     
    43444840
    43454841
    4346 \begin{comment}
    43474842\subsubsection{Modules / Packages}
    43484843
     
    44244919}
    44254920\end{cfa}
    4426 \end{comment}
    44274921
    44284922
     
    45855079
    45865080\subsection{Summary of Language Comparison}
    4587 
    4588 
    4589 \subsubsection[C++]{\CC}
    4590 
    4591 \Index*[C++]{\CC} is a general-purpose programming language.
     5081\end{comment}
     5082
     5083
     5084\subsection[C++]{\CC}
     5085
     5086\Index*[C++]{\CC{}} is a general-purpose programming language.
    45925087It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation. (Wikipedia)
    45935088
     
    46085103
    46095104
    4610 \subsubsection{Go}
     5105\subsection{Go}
    46115106
    46125107\Index*{Go}, also commonly referred to as golang, is a programming language developed at Google in 2007 [.].
     
    46245119
    46255120
    4626 \subsubsection{Rust}
     5121\subsection{Rust}
    46275122
    46285123\Index*{Rust} is a general-purpose, multi-paradigm, compiled programming language developed by Mozilla Research.
     
    46385133
    46395134
    4640 \subsubsection{D}
     5135\subsection{D}
    46415136
    46425137The \Index*{D} programming language is an object-oriented, imperative, multi-paradigm system programming
     
    46555150
    46565151
    4657 \section{Syntactic Anomalies}
    4658 
    4659 There are several ambiguous cases with operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be lexed as ©*©~\R{/}~©?*?© or ©*?©~\R{/}~©*?©.
    4660 Since it is common practise to put a unary operator juxtaposed to an identifier, \eg ©*i©, users will be annoyed if they cannot do this with respect to operator identifiers.
    4661 Even with this special hack, there are 5 general cases that cannot be handled.
    4662 The first case is for the function-call identifier ©?()©:
    4663 \begin{cfa}
    4664 int *§\textvisiblespace§?()();  // declaration: space required after '*'
    4665 *§\textvisiblespace§?()();              // expression: space required after '*'
    4666 \end{cfa}
    4667 Without the space, the string ©*?()© is ambiguous without N character look ahead;
    4668 it requires scanning ahead to determine if there is a ©'('©, which is the start of an argument/parameter list.
    4669 
    4670 The 4 remaining cases occur in expressions:
    4671 \begin{cfa}
    4672 i++§\textvisiblespace§?i:0;             // space required before '?'
    4673 i--§\textvisiblespace§?i:0;             // space required before '?'
    4674 i§\textvisiblespace§?++i:0;             // space required after '?'
    4675 i§\textvisiblespace§?--i:0;             // space required after '?'
    4676 \end{cfa}
    4677 In the first two cases, the string ©i++?© is ambiguous, where this string can be lexed as ©i© / ©++?© or ©i++© / ©?©;
    4678 it requires scanning ahead to determine if there is a ©'('©, which is the start of an argument list.
    4679 In the second two cases, the string ©?++x© is ambiguous, where this string can be lexed as ©?++© / ©x© or ©?© / y©++x©;
    4680 it requires scanning ahead to determine if there is a ©'('©, which is the start of an argument list.
    4681 
    4682 
    4683 \section{Incompatible}
    4684 
    4685 The following incompatibles exist between \CFA and C, and are similar to Annex C for \CC~\cite{ANSI14:C++}.
    4686 
    4687 \begin{enumerate}
    4688 \item
    4689 \begin{description}
    4690 \item[Change:] add new keywords \\
    4691 New keywords are added to \CFA (see~\VRef{s:NewKeywords}).
    4692 \item[Rationale:] keywords added to implement new semantics of \CFA.
    4693 \item[Effect on original feature:] change to semantics of well-defined feature. \\
    4694 Any ISO C programs using these keywords as identifiers are invalid \CFA programs.
    4695 \item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}):
    4696 \item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
    4697 \end{description}
    4698 
    4699 \item
    4700 \begin{description}
    4701 \item[Change:] type of character literal ©int© to ©char© to allow more intuitive overloading:
    4702 \begin{cfa}
    4703 int rtn( int i );
    4704 int rtn( char c );
    4705 rtn( 'x' );                                             §\C{// programmer expects 2nd rtn to be called}§
    4706 \end{cfa}
    4707 \item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
    4708 In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
    4709 \begin{cfa}
    4710 sout | 'x' | " " | (int)'x' | endl;
    4711 x 120
    4712 \end{cfa}
    4713 Having to cast ©'x'© to ©char© is non-intuitive.
    4714 \item[Effect on original feature:] change to semantics of well-defined feature that depend on:
    4715 \begin{cfa}
    4716 sizeof( 'x' ) == sizeof( int )
    4717 \end{cfa}
    4718 no long work the same in \CFA programs.
    4719 \item[Difficulty of converting:] simple
    4720 \item[How widely used:] programs that depend upon ©sizeof( 'x' )© are rare and can be changed to ©sizeof(char)©.
    4721 \end{description}
    4722 
    4723 \item
    4724 \begin{description}
    4725 \item[Change:] make string literals ©const©:
    4726 \begin{cfa}
    4727 char * p = "abc";                               §\C{// valid in C, deprecated in \CFA}§
    4728 char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
    4729 \end{cfa}
    4730 The type of a string literal is changed from ©[] char© to ©const [] char©.
    4731 Similarly, the type of a wide string literal is changed from ©[] wchar_t© to ©const [] wchar_t©.
    4732 \item[Rationale:] This change is a safety issue:
    4733 \begin{cfa}
    4734 char * p = "abc";
    4735 p[0] = 'w';                                             §\C{// segment fault or change constant literal}§
    4736 \end{cfa}
    4737 The same problem occurs when passing a string literal to a routine that changes its argument.
    4738 \item[Effect on original feature:] change to semantics of well-defined feature.
    4739 \item[Difficulty of converting:] simple syntactic transformation, because string literals can be converted to ©char *©.
    4740 \item[How widely used:] programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are rare.
    4741 \end{description}
    4742 
    4743 \item
    4744 \begin{description}
    4745 \item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
    4746 \begin{cfa}
    4747 int i;                                                  §\C{// forward definition}§
    4748 int *j = ®&i®;                                  §\C{// forward reference, valid in C, invalid in \CFA}§
    4749 int i = 0;                                              §\C{// definition}§
    4750 \end{cfa}
    4751 is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
    4752 This change makes it impossible to define mutually referential file-local static objects, if initializers are restricted to the syntactic forms of C. For example,
    4753 \begin{cfa}
    4754 struct X { int i; struct X *next; };
    4755 static struct X a;                              §\C{// forward definition}§
    4756 static struct X b = { 0, ®&a® };        §\C{// forward reference, valid in C, invalid in \CFA}§
    4757 static struct X a = { 1, &b };  §\C{// definition}§
    4758 \end{cfa}
    4759 \item[Rationale:] avoids having different initialization rules for builtin types and userdefined types.
    4760 \item[Effect on original feature:] change to semantics of well-defined feature.
    4761 \item[Difficulty of converting:] the initializer for one of a set of mutually-referential file-local static objects must invoke a routine call to achieve the initialization.
    4762 \item[How widely used:] seldom
    4763 \end{description}
    4764 
    4765 \item
    4766 \begin{description}
    4767 \item[Change:] have ©struct© introduce a scope for nested types:
    4768 \begin{cfa}
    4769 enum ®Colour® { R, G, B, Y, C, M };
    4770 struct Person {
    4771         enum ®Colour® { R, G, B };      §\C{// nested type}§
    4772         struct Face {                           §\C{// nested type}§
    4773                 ®Colour® Eyes, Hair;    §\C{// type defined outside (1 level)}§
    4774         };
    4775         ß.ß®Colour® shirt;                      §\C{// type defined outside (top level)}§
    4776         ®Colour® pants;                         §\C{// type defined same level}§
    4777         Face looks[10];                         §\C{// type defined same level}§
    4778 };
    4779 ®Colour® c = R;                                 §\C{// type/enum defined same level}§
    4780 Personß.ß®Colour® pc = Personß.ßR;      §\C{// type/enum defined inside}§
    4781 Personß.ßFace pretty;                   §\C{// type defined inside}§
    4782 \end{cfa}
    4783 In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing structure, i.e., the nested types are hoisted to the scope of the outer-most type, which is not useful and confusing.
    4784 \CFA is C \emph{incompatible} on this issue, and provides semantics similar to \Index*[C++]{\CC}.
    4785 Nested types are not hoisted and can be referenced using the field selection operator ``©.©'', unlike the \CC scope-resolution operator ``©::©''.
    4786 \item[Rationale:] ©struct© scope is crucial to \CFA as an information structuring and hiding mechanism.
    4787 \item[Effect on original feature:] change to semantics of well-defined feature.
    4788 \item[Difficulty of converting:] Semantic transformation.
    4789 \item[How widely used:] C programs rarely have nest types because they are equivalent to the hoisted version.
    4790 \end{description}
    4791 
    4792 \item
    4793 \begin{description}
    4794 \item[Change:] In C++, the name of a nested class is local to its enclosing class.
    4795 \item[Rationale:] C++ classes have member functions which require that classes establish scopes.
    4796 \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:
    4797 \begin{cfa}
    4798 struct Y;                                               §\C{// struct Y and struct X are at the same scope}§
    4799 struct X {
    4800 struct Y { /* ... */ } y;
    4801 };
    4802 \end{cfa}
    4803 All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of the enclosing struct could be exported to the scope of the enclosing struct.
    4804 Note: this is a consequence of the difference in scope rules, which is documented in 3.3.
    4805 \item[How widely used:] Seldom.
    4806 \end{description}
    4807 
    4808 \item
    4809 \begin{description}
    4810 \item[Change:] comma expression is disallowed as subscript
    4811 \item[Rationale:] safety issue to prevent subscripting error for multidimensional arrays: ©x[i,j]© instead of ©x[i][j]©, and this syntactic form then taken by \CFA for new style arrays.
    4812 \item[Effect on original feature:] change to semantics of well-defined feature.
    4813 \item[Difficulty of converting:] semantic transformation of ©x[i,j]© to ©x[(i,j)]©
    4814 \item[How widely used:] seldom.
    4815 \end{description}
    4816 \end{enumerate}
     5152\section{Syntax Ambiguities}
     5153
     5154C has a number of syntax ambiguities, which are resolved by taking the longest sequence of overlapping characters that constitute a token.
     5155For example, the program fragment ©x+++++y© is parsed as \lstinline[showspaces=true]@x ++ ++ + y@ because operator tokens ©++© and ©+© overlap.
     5156Unfortunately, the longest sequence violates a constraint on increment operators, even though the parse \lstinline[showspaces=true]@x ++ + ++ y@ might yield a correct expression.
     5157Hence, C programmers are aware that spaces have to added to disambiguate certain syntactic cases.
     5158
     5159In \CFA, there are ambiguous cases with dereference and operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be interpreted as:
     5160\begin{cfa}
     5161*?§\color{red}\textvisiblespace§*?              §\C{// dereference operator, dereference operator}§
     5162*§\color{red}\textvisiblespace§?*?              §\C{// dereference, multiplication operator}§
     5163\end{cfa}
     5164By default, the first interpretation is selected, which does not yield a meaningful parse.
     5165Therefore, \CFA does a lexical look-ahead for the second case, and backtracks to return the leading unary operator and reparses the trailing operator identifier.
     5166Otherwise a space is needed between the unary operator and operator identifier to disambiguate this common case.
     5167
     5168A similar issue occurs with the dereference, ©*?(...)©, and routine-call, ©?()(...)© identifiers.
     5169The ambiguity occurs when the deference operator has no parameters:
     5170\begin{cfa}
     5171*?()§\color{red}\textvisiblespace...§ ;
     5172*?()§\color{red}\textvisiblespace...§(...) ;
     5173\end{cfa}
     5174requiring arbitrary whitespace look-ahead for the routine-call parameter-list to disambiguate.
     5175However, the dereference operator \emph{must} have a parameter/argument to dereference ©*?(...)©.
     5176Hence, always interpreting the string ©*?()© as \lstinline[showspaces=true]@* ?()@ does not preclude any meaningful program.
     5177
     5178The remaining cases are with the increment/decrement operators and conditional expression, \eg:
     5179\begin{cfa}
     5180i++?§\color{red}\textvisiblespace...§(...);
     5181i?++§\color{red}\textvisiblespace...§(...);
     5182\end{cfa}
     5183requiring arbitrary whitespace look-ahead for the operator parameter-list, even though that interpretation is an incorrect expression (juxtaposed identifiers).
     5184Therefore, it is necessary to disambiguate these cases with a space:
     5185\begin{cfa}
     5186i++§\color{red}\textvisiblespace§? i : 0;
     5187i?§\color{red}\textvisiblespace§++i : 0;
     5188\end{cfa}
    48175189
    48185190
     
    48215193
    48225194\begin{quote2}
    4823 \begin{tabular}{lll}
     5195\begin{tabular}{llll}
    48245196\begin{tabular}{@{}l@{}}
    48255197©_AT©                   \\
     
    48295201©coroutine©             \\
    48305202©disable©               \\
    4831 ©dtype©                 \\
    4832 ©enable©                \\
    48335203\end{tabular}
    48345204&
    48355205\begin{tabular}{@{}l@{}}
     5206©dtype©                 \\
     5207©enable©                \\
    48365208©fallthrough©   \\
    48375209©fallthru©              \\
    48385210©finally©               \\
    48395211©forall©                \\
     5212\end{tabular}
     5213&
     5214\begin{tabular}{@{}l@{}}
    48405215©ftype©                 \\
    48415216©lvalue©                \\
    48425217©monitor©               \\
    48435218©mutex©                 \\
     5219©one_t©                 \\
     5220©otype©                 \\
    48445221\end{tabular}
    48455222&
    48465223\begin{tabular}{@{}l@{}}
    4847 ©one_t©                 \\
    4848 ©otype©                 \\
    48495224©throw©                 \\
    48505225©throwResume©   \\
     
    48585233
    48595234
     5235\section{Incompatible}
     5236
     5237The following incompatibles exist between \CFA and C, and are similar to Annex C for \CC~\cite{C++14}.
     5238
     5239
     5240\begin{enumerate}
     5241\item
     5242\begin{description}
     5243\item[Change:] add new keywords \\
     5244New keywords are added to \CFA (see~\VRef{s:CFAKeywords}).
     5245\item[Rationale:] keywords added to implement new semantics of \CFA.
     5246\item[Effect on original feature:] change to semantics of well-defined feature. \\
     5247Any \Celeven programs using these keywords as identifiers are invalid \CFA programs.
     5248\item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}).
     5249\item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
     5250\end{description}
     5251
     5252\item
     5253\begin{description}
     5254\item[Change:] drop K\&R C declarations \\
     5255K\&R declarations allow an implicit base-type of ©int©, if no type is specified, plus an alternate syntax for declaring parameters.
     5256\eg:
     5257\begin{cfa}
     5258x;                                                              §\C{// int x}§
     5259*y;                                                             §\C{// int *y}§
     5260f( p1, p2 );                                    §\C{// int f( int p1, int p2 );}§
     5261g( p1, p2 ) int p1, p2;                 §\C{// int g( int p1, int p2 );}§
     5262\end{cfa}
     5263\CFA supports K\&R routine definitions:
     5264\begin{cfa}
     5265f( a, b, c )                                    §\C{// default int return}§
     5266        int a, b; char c                        §\C{// K\&R parameter declarations}§
     5267{
     5268        ...
     5269}
     5270\end{cfa}
     5271\item[Rationale:] dropped from \Celeven standard.\footnote{
     5272At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and type name~\cite[\S~6.7.2(2)]{C11}}
     5273\item[Effect on original feature:] original feature is deprecated. \\
     5274Any old C programs using these K\&R declarations are invalid \CFA programs.
     5275\item[Difficulty of converting:] trivial to convert to \CFA.
     5276\item[How widely used:] existing usages are rare.
     5277\end{description}
     5278
     5279\item
     5280\begin{description}
     5281\item[Change:] type of character literal ©int© to ©char© to allow more intuitive overloading:
     5282\begin{cfa}
     5283int rtn( int i );
     5284int rtn( char c );
     5285rtn( 'x' );                                             §\C{// programmer expects 2nd rtn to be called}§
     5286\end{cfa}
     5287\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
     5288In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
     5289\begin{cfa}
     5290sout | 'x' | " " | (int)'x' | endl;
     5291x 120
     5292\end{cfa}
     5293Having to cast ©'x'© to ©char© is non-intuitive.
     5294\item[Effect on original feature:] change to semantics of well-defined feature that depend on:
     5295\begin{cfa}
     5296sizeof( 'x' ) == sizeof( int )
     5297\end{cfa}
     5298no long work the same in \CFA programs.
     5299\item[Difficulty of converting:] simple
     5300\item[How widely used:] programs that depend upon ©sizeof( 'x' )© are rare and can be changed to ©sizeof(char)©.
     5301\end{description}
     5302
     5303\item
     5304\begin{description}
     5305\item[Change:] make string literals ©const©:
     5306\begin{cfa}
     5307char * p = "abc";                               §\C{// valid in C, deprecated in \CFA}§
     5308char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
     5309\end{cfa}
     5310The type of a string literal is changed from ©[] char© to ©const [] char©.
     5311Similarly, the type of a wide string literal is changed from ©[] wchar_t© to ©const [] wchar_t©.
     5312\item[Rationale:] This change is a safety issue:
     5313\begin{cfa}
     5314char * p = "abc";
     5315p[0] = 'w';                                             §\C{// segment fault or change constant literal}§
     5316\end{cfa}
     5317The same problem occurs when passing a string literal to a routine that changes its argument.
     5318\item[Effect on original feature:] change to semantics of well-defined feature.
     5319\item[Difficulty of converting:] simple syntactic transformation, because string literals can be converted to ©char *©.
     5320\item[How widely used:] programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are rare.
     5321\end{description}
     5322
     5323\item
     5324\begin{description}
     5325\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
     5326\begin{cfa}
     5327int i;                                                  §\C{// forward definition}§
     5328int *j = ®&i®;                                  §\C{// forward reference, valid in C, invalid in \CFA}§
     5329int i = 0;                                              §\C{// definition}§
     5330\end{cfa}
     5331is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
     5332This change makes it impossible to define mutually referential file-local static objects, if initializers are restricted to the syntactic forms of C. For example,
     5333\begin{cfa}
     5334struct X { int i; struct X *next; };
     5335static struct X a;                              §\C{// forward definition}§
     5336static struct X b = { 0, ®&a® };        §\C{// forward reference, valid in C, invalid in \CFA}§
     5337static struct X a = { 1, &b };  §\C{// definition}§
     5338\end{cfa}
     5339\item[Rationale:] avoids having different initialization rules for builtin types and user-defined types.
     5340\item[Effect on original feature:] change to semantics of well-defined feature.
     5341\item[Difficulty of converting:] the initializer for one of a set of mutually-referential file-local static objects must invoke a routine call to achieve the initialization.
     5342\item[How widely used:] seldom
     5343\end{description}
     5344
     5345\item
     5346\begin{description}
     5347\item[Change:] have ©struct© introduce a scope for nested types:
     5348\begin{cfa}
     5349enum ®Colour® { R, G, B, Y, C, M };
     5350struct Person {
     5351        enum ®Colour® { R, G, B };      §\C{// nested type}§
     5352        struct Face {                           §\C{// nested type}§
     5353                ®Colour® Eyes, Hair;    §\C{// type defined outside (1 level)}§
     5354        };
     5355        ®.Colour® shirt;                        §\C{// type defined outside (top level)}§
     5356        ®Colour® pants;                         §\C{// type defined same level}§
     5357        Face looks[10];                         §\C{// type defined same level}§
     5358};
     5359®Colour® c = R;                                 §\C{// type/enum defined same level}§
     5360Person®.Colour® pc = Person®.®R;        §\C{// type/enum defined inside}§
     5361Person®.®Face pretty;                   §\C{// type defined inside}§
     5362\end{cfa}
     5363In 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.
     5364\CFA is C \emph{incompatible} on this issue, and provides semantics similar to \Index*[C++]{\CC{}}.
     5365Nested types are not hoisted and can be referenced using the field selection operator ``©.©'', unlike the \CC scope-resolution operator ``©::©''.
     5366\item[Rationale:] ©struct© scope is crucial to \CFA as an information structuring and hiding mechanism.
     5367\item[Effect on original feature:] change to semantics of well-defined feature.
     5368\item[Difficulty of converting:] Semantic transformation.
     5369\item[How widely used:] C programs rarely have nest types because they are equivalent to the hoisted version.
     5370\end{description}
     5371
     5372\item
     5373\begin{description}
     5374\item[Change:] In C++, the name of a nested class is local to its enclosing class.
     5375\item[Rationale:] C++ classes have member functions which require that classes establish scopes.
     5376\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:
     5377\begin{cfa}
     5378struct Y;                                               §\C{// struct Y and struct X are at the same scope}§
     5379struct X {
     5380        struct Y { /* ... */ } y;
     5381};
     5382\end{cfa}
     5383All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of the enclosing struct could be exported to the scope of the enclosing struct.
     5384Note: this is a consequence of the difference in scope rules, which is documented in 3.3.
     5385\item[How widely used:] Seldom.
     5386\end{description}
     5387
     5388\item
     5389\begin{description}
     5390\item[Change:] comma expression is disallowed as subscript
     5391\item[Rationale:] safety issue to prevent subscripting error for multidimensional arrays: ©x[i,j]© instead of ©x[i][j]©, and this syntactic form then taken by \CFA for new style arrays.
     5392\item[Effect on original feature:] change to semantics of well-defined feature.
     5393\item[Difficulty of converting:] semantic transformation of ©x[i,j]© to ©x[(i,j)]©
     5394\item[How widely used:] seldom.
     5395\end{description}
     5396\end{enumerate}
     5397
     5398
    48605399\section{Standard Headers}
    48615400\label{s:StandardHeaders}
    48625401
    4863 C11 prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list:
     5402\Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list:
    48645403\begin{quote2}
    4865 \begin{tabular}{lll|l}
    4866 \multicolumn{3}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
     5404\lstset{deletekeywords={float}}
     5405\begin{tabular}{@{}llll|l@{}}
     5406\multicolumn{4}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
    48675407\hline
    4868 assert.h        & math.h                & stdlib.h              & unistd.h      \\
    4869 complex.h       & setjmp.h              & stdnoreturn.h & gmp.h         \\
    4870 ctype.h         & signal.h              & string.h              \\
    4871 errno.h         & stdalign.h    & tgmath.h              \\
    4872 fenv.h          & stdarg.h              & threads.h             \\
    4873 float.h         & stdatomic.h   & time.h                \\
    4874 inttypes.h      & stdbool.h             & uchar.h               \\
    4875 iso646.h        & stddef.h              & wchar.h               \\
    4876 limits.h        & stdint.h              & wctype.h              \\
    4877 locale.h        & stdio.h               &                               \\
     5408\begin{tabular}{@{}l@{}}
     5409\Indexc{assert.h}               \\
     5410\Indexc{complex.h}              \\
     5411\Indexc{ctype.h}                \\
     5412\Indexc{errno.h}                \\
     5413\Indexc{fenv.h}                 \\
     5414\Indexc{float.h}                \\
     5415\Indexc{inttypes.h}             \\
     5416\Indexc{iso646.h}               \\
     5417\end{tabular}
     5418&
     5419\begin{tabular}{@{}l@{}}
     5420\Indexc{limits.h}               \\
     5421\Indexc{locale.h}               \\
     5422\Indexc{math.h}                 \\
     5423\Indexc{setjmp.h}               \\
     5424\Indexc{signal.h}               \\
     5425\Indexc{stdalign.h}             \\
     5426\Indexc{stdarg.h}               \\
     5427\Indexc{stdatomic.h}    \\
     5428\end{tabular}
     5429&
     5430\begin{tabular}{@{}l@{}}
     5431\Indexc{stdbool.h}              \\
     5432\Indexc{stddef.h}               \\
     5433\Indexc{stdint.h}               \\
     5434\Indexc{stdio.h}                \\
     5435\Indexc{stdlib.h}               \\
     5436\Indexc{stdnoreturn.h}  \\
     5437\Indexc{string.h}               \\
     5438\Indexc{tgmath.h}               \\
     5439\end{tabular}
     5440&
     5441\begin{tabular}{@{}l@{}}
     5442\Indexc{threads.h}              \\
     5443\Indexc{time.h}                 \\
     5444\Indexc{uchar.h}                \\
     5445\Indexc{wchar.h}                \\
     5446\Indexc{wctype.h}               \\
     5447                                                \\
     5448                                                \\
     5449                                                \\
     5450\end{tabular}
     5451&
     5452\begin{tabular}{@{}l@{}}
     5453\Indexc{unistd.h}               \\
     5454\Indexc{gmp.h}                  \\
     5455                                                \\
     5456                                                \\
     5457                                                \\
     5458                                                \\
     5459                                                \\
     5460                                                \\
     5461\end{tabular}
    48785462\end{tabular}
    48795463\end{quote2}
    4880 For the prescribed head-files, \CFA implicitly wraps their includes in an ©extern "C"©;
     5464For the prescribed head-files, \CFA uses header interposition to wraps these includes in an ©extern "C"©;
    48815465hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}).
    48825466All other C header files must be explicitly wrapped in ©extern "C"© to prevent name mangling.
     5467For \Index*[C++]{\CC{}}, the name-mangling issue is handled implicitly because most C header-files are augmented with checks for preprocessor variable ©__cplusplus©, which adds appropriate ©extern "C"© qualifiers.
    48835468
    48845469
     
    48865471\label{s:StandardLibrary}
    48875472
    4888 The goal of the \CFA standard-library is to wrap many of the existing C library-routines that are explicitly polymorphic into implicitly polymorphic versions.
    4889 
    4890 
    4891 \subsection{malloc}
     5473The \CFA standard-library wraps explicitly-polymorphic C routines into implicitly-polymorphic versions.
     5474
     5475
     5476\subsection{Storage Management}
     5477
     5478The storage-management routines extend their C equivalents by overloading, alternate names, providing shallow type-safety, and removing the need to specify the allocation size for non-array types.
     5479
     5480Storage management provides the following capabilities:
     5481\begin{description}
     5482\item[fill]
     5483after allocation the storage is filled with a specified character.
     5484\item[resize]
     5485an existing allocation is decreased or increased in size.
     5486In either case, new storage may or may not be allocated and, if there is a new allocation, as much data from the existing allocation is copied.
     5487For an increase in storage size, new storage after the copied data may be filled.
     5488\item[alignment]
     5489an allocation starts on a specified memory boundary, e.g., an address multiple of 64 or 128 for cache-line purposes.
     5490\item[array]
     5491the allocation size is scaled to the specified number of array elements.
     5492An array may be filled, resized, or aligned.
     5493\end{description}
     5494The table shows allocation routines supporting different combinations of storage-management capabilities:
     5495\begin{center}
     5496\begin{tabular}{@{}lr|l|l|l|l@{}}
     5497                &                                       & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
     5498\hline
     5499C               & ©malloc©                      & no                    & no            & no            & no    \\
     5500                & ©calloc©                      & yes (0 only)  & no            & no            & yes   \\
     5501                & ©realloc©                     & no/copy               & yes           & no            & no    \\
     5502                & ©memalign©            & no                    & no            & yes           & no    \\
     5503                & ©posix_memalign©      & no                    & no            & yes           & no    \\
     5504C11             & ©aligned_alloc©       & no                    & no            & yes           & no    \\
     5505\CFA    & ©alloc©                       & no/copy/yes   & no/yes        & no            & yes   \\
     5506                & ©align_alloc©         & no/yes                & no            & yes           & yes   \\
     5507\end{tabular}
     5508\end{center}
     5509It is impossible to resize with alignment because the underlying ©realloc© allocates storage if more space is needed, and it does not honour alignment from the original allocation.
    48925510
    48935511\leavevmode
    48945512\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    4895 forall( otype T ) T * malloc( void );§\indexc{malloc}§
    4896 forall( otype T ) T * malloc( char fill );
    4897 forall( otype T ) T * malloc( T * ptr, size_t size );
    4898 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
    4899 forall( otype T ) T * calloc( size_t nmemb );§\indexc{calloc}§
    4900 forall( otype T ) T * realloc( T * ptr, size_t size );§\indexc{ato}§
    4901 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
    4902 
    4903 forall( otype T ) T * aligned_alloc( size_t alignment );§\indexc{ato}§
    4904 forall( otype T ) T * memalign( size_t alignment );             // deprecated
    4905 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
    4906 
    4907 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
    4908 forall( otype T ) T * memset( T * ptr );                                // remove when default value available
    4909 \end{cfa}
    4910 
    4911 
    4912 \subsection{ato / strto}
     5513// C unsafe allocation
     5514extern "C" {
     5515void * mallac( size_t size );§\indexc{memset}§
     5516void * calloc( size_t dim, size_t size );§\indexc{calloc}§
     5517void * realloc( void * ptr, size_t size );§\indexc{realloc}§
     5518void * memalign( size_t align, size_t size );§\indexc{memalign}§
     5519int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
     5520}
     5521
     5522// §\CFA§ safe equivalents, i.e., implicit size specification
     5523forall( dtype T | sized(T) ) T * malloc( void );
     5524forall( dtype T | sized(T) ) T * calloc( size_t dim );
     5525forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );
     5526forall( dtype T | sized(T) ) T * memalign( size_t align );
     5527forall( dtype T | sized(T) ) T * aligned_alloc( size_t align );
     5528forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align );
     5529
     5530// §\CFA§ safe general allocation, fill, resize, array
     5531forall( dtype T | sized(T) ) T * alloc( void );§\indexc{alloc}§
     5532forall( dtype T | sized(T) ) T * alloc( char fill );
     5533forall( dtype T | sized(T) ) T * alloc( size_t dim );
     5534forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill );
     5535forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim );
     5536forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
     5537
     5538// §\CFA§ safe general allocation, align, fill, array
     5539forall( dtype T | sized(T) ) T * align_alloc( size_t align );
     5540forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill );
     5541forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim );
     5542forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill );
     5543
     5544// C unsafe initialization/copy
     5545extern "C" {
     5546void * memset( void * dest, int c, size_t size );
     5547void * memcpy( void * dest, const void * src, size_t size );
     5548}
     5549
     5550// §\CFA§ safe initialization/copy, i.e., implicit size specification
     5551forall( dtype T | sized(T) ) T * memset( T * dest, char c );§\indexc{memset}§
     5552forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
     5553
     5554// §\CFA§ safe initialization/copy array
     5555forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c );
     5556forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim );
     5557
     5558// §\CFA§ allocation/deallocation and constructor/destructor
     5559forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );§\indexc{new}§
     5560forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );§\indexc{delete}§
     5561forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
     5562  void delete( T * ptr, Params rest );
     5563
     5564// §\CFA§ allocation/deallocation and constructor/destructor, array
     5565forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
     5566forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
     5567forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
     5568  void adelete( size_t dim, T arr[], Params rest );
     5569\end{cfa}
     5570
     5571
     5572\subsection{Conversion}
    49135573
    49145574\leavevmode
     
    49425602
    49435603
    4944 \subsection{bsearch / qsort}
     5604\subsection{Search / Sort}
    49455605
    49465606\leavevmode
    49475607\begin{cfa}[aboveskip=0pt,belowskip=0pt]
     5608forall( otype T | { int ?<?( T, T ); } )        §\C{// location}§
     5609T * bsearch( T key, const T * arr, size_t dim );§\indexc{bsearch}§
     5610
     5611forall( otype T | { int ?<?( T, T ); } )        §\C{// position}§
     5612unsigned int bsearch( T key, const T * arr, size_t dim );
     5613
    49485614forall( otype T | { int ?<?( T, T ); } )
    4949 T * bsearch( const T key, const T * arr, size_t dimension );§\indexc{bsearch}§
    4950 
    4951 forall( otype T | { int ?<?( T, T ); } )
    4952 void qsort( const T * arr, size_t dimension );§\indexc{qsort}§
    4953 \end{cfa}
    4954 
    4955 
    4956 \subsection{abs}
     5615void qsort( const T * arr, size_t dim );§\indexc{qsort}§
     5616\end{cfa}
     5617
     5618
     5619\subsection{Absolute Value}
    49575620
    49585621\leavevmode
    49595622\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    4960 char abs( char );§\indexc{abs}§
     5623unsigned char abs( signed char );§\indexc{abs}§
    49615624int abs( int );
    4962 long int abs( long int );
    4963 long long int abs( long long int );
     5625unsigned long int abs( long int );
     5626unsigned long long int abs( long long int );
    49645627float abs( float );
    49655628double abs( double );
     
    49685631double abs( double _Complex );
    49695632long double abs( long double _Complex );
    4970 \end{cfa}
    4971 
    4972 
    4973 \subsection{random}
     5633forall( otype T | { void ?{}( T *, zero_t ); int ?<?( T, T ); T -?( T ); } )
     5634T abs( T );
     5635\end{cfa}
     5636
     5637
     5638\subsection{Random Numbers}
    49745639
    49755640\leavevmode
     
    49895654
    49905655
    4991 \subsection{min / max / clamp / swap}
     5656\subsection{Algorithms}
    49925657
    49935658\leavevmode
    49945659\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    4995 forall( otype T | { int ?<?( T, T ); } )
    4996 T min( const T t1, const T t2 );§\indexc{min}§
    4997 
    4998 forall( otype T | { int ?>?( T, T ); } )
    4999 T max( const T t1, const T t2 );§\indexc{max}§
    5000 
    5001 forall( otype T | { T min( T, T ); T max( T, T ); } )
    5002 T clamp( T value, T min_val, T max_val );§\indexc{clamp}§
    5003 
    5004 forall( otype T )
    5005 void swap( T * t1, T * t2 );§\indexc{swap}§
     5660forall( otype T | { int ?<?( T, T ); } ) T min( T t1, T t2 );§\indexc{min}§
     5661forall( otype T | { int ?>?( T, T ); } ) T max( T t1, T t2 );§\indexc{max}§
     5662forall( otype T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );§\indexc{clamp}§
     5663forall( otype T ) void swap( T * t1, T * t2 );§\indexc{swap}§
    50065664\end{cfa}
    50075665
     
    50105668\label{s:Math Library}
    50115669
    5012 The goal of the \CFA math-library is to wrap many of the existing C math library-routines that are explicitly polymorphic into implicitly polymorphic versions.
     5670The \CFA math-library wraps explicitly-polymorphic C math-routines into implicitly-polymorphic versions.
    50135671
    50145672
     
    50175675\leavevmode
    50185676\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    5019 float fabs( float );§\indexc{fabs}§
    5020 double fabs( double );
    5021 long double fabs( long double );
    5022 float cabs( float _Complex );
    5023 double cabs( double _Complex );
    5024 long double cabs( long double _Complex );
    5025 
    50265677float ?%?( float, float );§\indexc{fmod}§
    50275678float fmod( float, float );
     
    53786029
    53796030
     6031\section{Multi-precision Integers}
     6032\label{s:MultiPrecisionIntegers}
     6033
     6034\CFA has an interface to the GMP \Index{multi-precision} signed-integers~\cite{GMP}, similar to the \CC interface provided by GMP.
     6035The \CFA interface wraps GMP routines into operator routines to make programming with multi-precision integers identical to using fixed-sized integers.
     6036The \CFA type name for multi-precision signed-integers is \Indexc{Int} and the header file is \Indexc{gmp}.
     6037
     6038\begin{cfa}
     6039void ?{}( Int * this );                                 §\C{// constructor}§
     6040void ?{}( Int * this, Int init );
     6041void ?{}( Int * this, zero_t );
     6042void ?{}( Int * this, one_t );
     6043void ?{}( Int * this, signed long int init );
     6044void ?{}( Int * this, unsigned long int init );
     6045void ?{}( Int * this, const char * val );
     6046void ^?{}( Int * this );
     6047
     6048Int ?=?( Int * lhs, Int rhs );                  §\C{// assignment}§
     6049Int ?=?( Int * lhs, long int rhs );
     6050Int ?=?( Int * lhs, unsigned long int rhs );
     6051Int ?=?( Int * lhs, const char * rhs );
     6052
     6053char ?=?( char * lhs, Int rhs );
     6054short int ?=?( short int * lhs, Int rhs );
     6055int ?=?( int * lhs, Int rhs );
     6056long int ?=?( long int * lhs, Int rhs );
     6057unsigned char ?=?( unsigned char * lhs, Int rhs );
     6058unsigned short int ?=?( unsigned short int * lhs, Int rhs );
     6059unsigned int ?=?( unsigned int * lhs, Int rhs );
     6060unsigned long int ?=?( unsigned long int * lhs, Int rhs );
     6061
     6062long int narrow( Int val );
     6063unsigned long int narrow( Int val );
     6064
     6065int ?==?( Int oper1, Int oper2 );               §\C{// comparison}§
     6066int ?==?( Int oper1, long int oper2 );
     6067int ?==?( long int oper2, Int oper1 );
     6068int ?==?( Int oper1, unsigned long int oper2 );
     6069int ?==?( unsigned long int oper2, Int oper1 );
     6070
     6071int ?!=?( Int oper1, Int oper2 );
     6072int ?!=?( Int oper1, long int oper2 );
     6073int ?!=?( long int oper1, Int oper2 );
     6074int ?!=?( Int oper1, unsigned long int oper2 );
     6075int ?!=?( unsigned long int oper1, Int oper2 );
     6076
     6077int ?<?( Int oper1, Int oper2 );
     6078int ?<?( Int oper1, long int oper2 );
     6079int ?<?( long int oper2, Int oper1 );
     6080int ?<?( Int oper1, unsigned long int oper2 );
     6081int ?<?( unsigned long int oper2, Int oper1 );
     6082
     6083int ?<=?( Int oper1, Int oper2 );
     6084int ?<=?( Int oper1, long int oper2 );
     6085int ?<=?( long int oper2, Int oper1 );
     6086int ?<=?( Int oper1, unsigned long int oper2 );
     6087int ?<=?( unsigned long int oper2, Int oper1 );
     6088
     6089int ?>?( Int oper1, Int oper2 );
     6090int ?>?( Int oper1, long int oper2 );
     6091int ?>?( long int oper1, Int oper2 );
     6092int ?>?( Int oper1, unsigned long int oper2 );
     6093int ?>?( unsigned long int oper1, Int oper2 );
     6094
     6095int ?>=?( Int oper1, Int oper2 );
     6096int ?>=?( Int oper1, long int oper2 );
     6097int ?>=?( long int oper1, Int oper2 );
     6098int ?>=?( Int oper1, unsigned long int oper2 );
     6099int ?>=?( unsigned long int oper1, Int oper2 );
     6100
     6101Int +?( Int oper );                                             §\C{// arithmetic}§
     6102Int -?( Int oper );
     6103Int ~?( Int oper );
     6104
     6105Int ?&?( Int oper1, Int oper2 );
     6106Int ?&?( Int oper1, long int oper2 );
     6107Int ?&?( long int oper1, Int oper2 );
     6108Int ?&?( Int oper1, unsigned long int oper2 );
     6109Int ?&?( unsigned long int oper1, Int oper2 );
     6110Int ?&=?( Int * lhs, Int rhs );
     6111
     6112Int ?|?( Int oper1, Int oper2 );
     6113Int ?|?( Int oper1, long int oper2 );
     6114Int ?|?( long int oper1, Int oper2 );
     6115Int ?|?( Int oper1, unsigned long int oper2 );
     6116Int ?|?( unsigned long int oper1, Int oper2 );
     6117Int ?|=?( Int * lhs, Int rhs );
     6118
     6119Int ?^?( Int oper1, Int oper2 );
     6120Int ?^?( Int oper1, long int oper2 );
     6121Int ?^?( long int oper1, Int oper2 );
     6122Int ?^?( Int oper1, unsigned long int oper2 );
     6123Int ?^?( unsigned long int oper1, Int oper2 );
     6124Int ?^=?( Int * lhs, Int rhs );
     6125
     6126Int ?+?( Int addend1, Int addend2 );
     6127Int ?+?( Int addend1, long int addend2 );
     6128Int ?+?( long int addend2, Int addend1 );
     6129Int ?+?( Int addend1, unsigned long int addend2 );
     6130Int ?+?( unsigned long int addend2, Int addend1 );
     6131Int ?+=?( Int * lhs, Int rhs );
     6132Int ?+=?( Int * lhs, long int rhs );
     6133Int ?+=?( Int * lhs, unsigned long int rhs );
     6134Int ++?( Int * lhs );
     6135Int ?++( Int * lhs );
     6136
     6137Int ?-?( Int minuend, Int subtrahend );
     6138Int ?-?( Int minuend, long int subtrahend );
     6139Int ?-?( long int minuend, Int subtrahend );
     6140Int ?-?( Int minuend, unsigned long int subtrahend );
     6141Int ?-?( unsigned long int minuend, Int subtrahend );
     6142Int ?-=?( Int * lhs, Int rhs );
     6143Int ?-=?( Int * lhs, long int rhs );
     6144Int ?-=?( Int * lhs, unsigned long int rhs );
     6145Int --?( Int * lhs );
     6146Int ?--( Int * lhs );
     6147
     6148Int ?*?( Int multiplicator, Int multiplicand );
     6149Int ?*?( Int multiplicator, long int multiplicand );
     6150Int ?*?( long int multiplicand, Int multiplicator );
     6151Int ?*?( Int multiplicator, unsigned long int multiplicand );
     6152Int ?*?( unsigned long int multiplicand, Int multiplicator );
     6153Int ?*=?( Int * lhs, Int rhs );
     6154Int ?*=?( Int * lhs, long int rhs );
     6155Int ?*=?( Int * lhs, unsigned long int rhs );
     6156
     6157Int ?/?( Int dividend, Int divisor );
     6158Int ?/?( Int dividend, unsigned long int divisor );
     6159Int ?/?( unsigned long int dividend, Int divisor );
     6160Int ?/?( Int dividend, long int divisor );
     6161Int ?/?( long int dividend, Int divisor );
     6162Int ?/=?( Int * lhs, Int rhs );
     6163Int ?/=?( Int * lhs, long int rhs );
     6164Int ?/=?( Int * lhs, unsigned long int rhs );
     6165
     6166[ Int, Int ] div( Int dividend, Int divisor );
     6167[ Int, Int ] div( Int dividend, unsigned long int divisor );
     6168
     6169Int ?%?( Int dividend, Int divisor );
     6170Int ?%?( Int dividend, unsigned long int divisor );
     6171Int ?%?( unsigned long int dividend, Int divisor );
     6172Int ?%?( Int dividend, long int divisor );
     6173Int ?%?( long int dividend, Int divisor );
     6174Int ?%=?( Int * lhs, Int rhs );
     6175Int ?%=?( Int * lhs, long int rhs );
     6176Int ?%=?( Int * lhs, unsigned long int rhs );
     6177
     6178Int ?<<?( Int shiften, mp_bitcnt_t shift );
     6179Int ?<<=?( Int * lhs, mp_bitcnt_t shift );
     6180Int ?>>?( Int shiften, mp_bitcnt_t shift );
     6181Int ?>>=?( Int * lhs, mp_bitcnt_t shift );
     6182
     6183Int abs( Int oper );                                    §\C{// number functions}§
     6184Int fact( unsigned long int N );
     6185Int gcd( Int oper1, Int oper2 );
     6186Int pow( Int base, unsigned long int exponent );
     6187Int pow( unsigned long int base, unsigned long int exponent );
     6188void srandom( gmp_randstate_t state );
     6189Int random( gmp_randstate_t state, mp_bitcnt_t n );
     6190Int random( gmp_randstate_t state, Int n );
     6191Int random( gmp_randstate_t state, mp_size_t max_size );
     6192int sgn( Int oper );
     6193Int sqrt( Int oper );
     6194
     6195forall( dtype istype | istream( istype ) ) istype * ?|?( istype * is, Int * mp );  §\C{// I/O}§
     6196forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype * os, Int mp );
     6197\end{cfa}
     6198
     6199The following factorial programs contrast using GMP with the \CFA and C interfaces, where the output from these programs appears in \VRef[Figure]{f:MultiPrecisionFactorials}.
     6200(Compile with flag \Indexc{-lgmp} to link with the GMP library.)
     6201\begin{quote2}
     6202\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
     6203\multicolumn{1}{c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}}      \\
     6204\hline
     6205\begin{cfa}
     6206#include <gmp>§\indexc{gmp}§
     6207int main( void ) {
     6208        sout | "Factorial Numbers" | endl;
     6209        Int fact = 1;
     6210
     6211        sout | 0 | fact | endl;
     6212        for ( unsigned int i = 1; i <= 40; i += 1 ) {
     6213                fact *= i;
     6214                sout | i | fact | endl;
     6215        }
     6216}
     6217\end{cfa}
     6218&
     6219\begin{cfa}
     6220#include <gmp.h>§\indexc{gmp.h}§
     6221int main( void ) {
     6222        ®gmp_printf®( "Factorial Numbers\n" );
     6223        ®mpz_t® fact;
     6224        ®mpz_init_set_ui®( fact, 1 );
     6225        ®gmp_printf®( "%d %Zd\n", 0, fact );
     6226        for ( unsigned int i = 1; i <= 40; i += 1 ) {
     6227                ®mpz_mul_ui®( fact, fact, i );
     6228                ®gmp_printf®( "%d %Zd\n", i, fact );
     6229        }
     6230}
     6231\end{cfa}
     6232\end{tabular}
     6233\end{quote2}
     6234
     6235\begin{figure}
     6236\begin{cfa}
     6237Factorial Numbers
     62380 1
     62391 1
     62402 2
     62413 6
     62424 24
     62435 120
     62446 720
     62457 5040
     62468 40320
     62479 362880
     624810 3628800
     624911 39916800
     625012 479001600
     625113 6227020800
     625214 87178291200
     625315 1307674368000
     625416 20922789888000
     625517 355687428096000
     625618 6402373705728000
     625719 121645100408832000
     625820 2432902008176640000
     625921 51090942171709440000
     626022 1124000727777607680000
     626123 25852016738884976640000
     626224 620448401733239439360000
     626325 15511210043330985984000000
     626426 403291461126605635584000000
     626527 10888869450418352160768000000
     626628 304888344611713860501504000000
     626729 8841761993739701954543616000000
     626830 265252859812191058636308480000000
     626931 8222838654177922817725562880000000
     627032 263130836933693530167218012160000000
     627133 8683317618811886495518194401280000000
     627234 295232799039604140847618609643520000000
     627335 10333147966386144929666651337523200000000
     627436 371993326789901217467999448150835200000000
     627537 13763753091226345046315979581580902400000000
     627638 523022617466601111760007224100074291200000000
     627739 20397882081197443358640281739902897356800000000
     627840 815915283247897734345611269596115894272000000000
     6279\end{cfa}
     6280\caption{Multi-precision Factorials}
     6281\label{f:MultiPrecisionFactorials}
     6282\end{figure}
     6283
     6284
    53806285\section{Rational Numbers}
    53816286\label{s:RationalNumbers}
     
    53906295}; // Rational
    53916296
    5392 // constants
    5393 extern struct Rational 0;
    5394 extern struct Rational 1;
    5395 
    5396 // constructors
    5397 Rational rational();
     6297Rational rational();                                    §\C{// constructors}§
    53986298Rational rational( long int n );
    53996299Rational rational( long int n, long int d );
    5400 
    5401 // getter/setter for numerator/denominator
    5402 long int numerator( Rational r );
     6300void ?{}( Rational * r, zero_t );
     6301void ?{}( Rational * r, one_t );
     6302
     6303long int numerator( Rational r );               §\C{// numerator/denominator getter/setter}§
    54036304long int numerator( Rational r, long int n );
    54046305long int denominator( Rational r );
    54056306long int denominator( Rational r, long int d );
    54066307
    5407 // comparison
    5408 int ?==?( Rational l, Rational r );
     6308int ?==?( Rational l, Rational r );             §\C{// comparison}§
    54096309int ?!=?( Rational l, Rational r );
    54106310int ?<?( Rational l, Rational r );
     
    54136313int ?>=?( Rational l, Rational r );
    54146314
    5415 // arithmetic
    5416 Rational -?( Rational r );
     6315Rational -?( Rational r );                              §\C{// arithmetic}§
    54176316Rational ?+?( Rational l, Rational r );
    54186317Rational ?-?( Rational l, Rational r );
     
    54206319Rational ?/?( Rational l, Rational r );
    54216320
    5422 // conversion
    5423 double widen( Rational r );
     6321double widen( Rational r );                             §\C{// conversion}§
    54246322Rational narrow( double f, long int md );
    54256323
    5426 // I/O
    5427 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
     6324forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * ); // I/O
    54286325forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
    54296326\end{cfa}
  • doc/working/resolver_design.md

    r9c951e3 rb1e63ac5  
    4141ensure that they are two-arg functions (this restriction may be valuable
    4242regardless).
     43
     44Regardless of syntax, there should be a type assertion that expresses `From`
     45is convertable to `To`.
     46If user-defined conversions are not added to the language,
     47`void ?{} ( To*, From )` may be a suitable representation, relying on
     48conversions on the argument types to account for transitivity.
     49On the other hand, `To*` should perhaps match its target type exactly, so
     50another assertion syntax specific to conversions may be required, e.g.
     51`From -> To`.
    4352
    4453### Constructor Idiom ###
Note: See TracChangeset for help on using the changeset viewer.