Changeset 1048b31 for doc/user


Ignore:
Timestamp:
May 2, 2016, 3:28:16 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1b7ea43
Parents:
1f6e009 (diff), e945826 (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 global-init

Location:
doc/user
Files:
1 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • doc/user/Makefile

    r1f6e009 r1048b31  
    11## Define the appropriate configuration variables.
    22
    3 TeXLIB = .::
     3TeXLIB = .:../bibliography/:../LaTeXmacros/:
    44LaTeX  = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex
    5 BibTeX = BSTINPUTS=${TeXLIB} && export BSTINPUTS && bibtex
     5BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex
    66
    77## Define the text source files.
     
    1212
    1313FIGURES = ${addsuffix .tex, \
     14Cdecl \
    1415}
    1516
     
    4344        dvips $< -o $@
    4445
    45 ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex ${basename ${DOCUMENT}}.bib /usr/local/bibliographies/pl.bib
     46${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \
     47                ../LaTeXmacros/common.tex ../LaTeXmacros/indexstyle ../bibliography/cfa.bib
    4648        # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
    4749        if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi
     
    5355        -${BibTeX} ${basename $@}
    5456        # Make index from *.aux entries and input index at end of document
    55         makeindex -s indexstyle ${basename $@}.idx
     57        makeindex -s ../LaTeXmacros/indexstyle ${basename $@}.idx
    5658        ${LaTeX} ${basename $@}.tex
    5759        # Run again to get index title into table of contents
  • doc/user/user.tex

    r1f6e009 r1048b31  
     1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
     2%%
     3%% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     4%%
     5%% The contents of this file are covered under the licence agreement in the
     6%% file "LICENCE" distributed with Cforall.
     7%%
     8%% user.tex --
     9%%
     10%% Author           : Peter A. Buhr
     11%% Created On       : Wed Apr  6 14:53:29 2016
     12%% Last Modified By : Peter A. Buhr
     13%% Last Modified On : Sat Apr 30 13:54:32 2016
     14%% Update Count     : 221
     15%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     16
    117% requires tex packages: texlive-base texlive-latex-base tex-common texlive-humanities texlive-latex-extra texlive-fonts-recommended
     18
     19% red highlighting ®...® (registered trademark sumbol)
     20% blue highlighting ©...© (copyright symbol)
     21% latex escape §...§ (section symbol)
     22% keyword escape ¶...¶ (pilcrow symbol)
     23% math escape $...$ (dollar symbol)
    224
    325\documentclass[openright,twoside]{article}
     
    527
    628% Latex packages used in the document.
    7 
     29\usepackage[T1]{fontenc}                                % allow Latin1 (extended ASCII) characters
     30\usepackage{textcomp}
     31\usepackage[latin1]{inputenc}
     32\usepackage{upquote}
    833\usepackage{fullpage,times}
     34\usepackage{epic,eepic}
    935\usepackage{xspace}
    1036\usepackage{varioref}
     
    1238\usepackage{footmisc}
    1339\usepackage{comment}
    14 \usepackage{latexsym}                                   % \Box
    15 \usepackage{mathptmx}                                   % better math font with "times"
     40\usepackage{latexsym}                                   % \Box
     41\usepackage{mathptmx}                                   % better math font with "times"
    1642\usepackage[pagewise]{lineno}
    1743\renewcommand{\linenumberfont}{\scriptsize\sffamily}
     
    2248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2349
     50% Bespoke macros used in the document.
     51\input{common}
     52
     53%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     54
    2455% Names used in the document.
    2556
    26 \newcommand{\CFA}{C$\forall$\xspace}    % set language symbolic name
    27 \newcommand{\CFL}{Cforall\xspace}               % set language text name
    28 \newcommand{\CC}{C\kern-.1em\hbox{+\kern-.25em+}\xspace} % CC symbolic name
    29 \def\c11{ISO/IEC C} % C11 name (cannot have numbers in latex command name)
     57\newcommand{\Version}{1.0.0}
    3058\newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace}
    3159
    3260%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3361
    34 % Bespoke macros used in the document.
    35 
    36 \makeatletter
    37 % allow escape sequence in lstinline
    38 %\usepackage{etoolbox}
    39 %\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}}
    40 
    41 \renewcommand\small{%
    42    \@setfontsize\small{8.5}{11}%
    43    \abovedisplayskip 8.5pt \@plus 3pt \@minus 4pt
    44    \abovedisplayshortskip \z@ \@plus 2pt
    45    \belowdisplayshortskip 4pt \@plus 2pt \@minus 2pt
    46    \def\@listi{\leftmargin\leftmargini
    47                \topsep 4pt \@plus 2pt \@minus 2pt
    48                \parsep 2pt \@pluspt \@minuspt
    49                \itemsep \parsep}%
    50    \belowdisplayskip \abovedisplayskip
    51 }
    52 \usepackage{relsize}            % must be after change to small
    53 
    54 \renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}}
    55 \renewenvironment{itemize}{\begin{list}{\labelitemi}{\topsep=5pt\itemsep=5pt\parsep=0pt}}{\end{list}}
    56 
    57 %  Reduce size of section titles
    58 \renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\large\bfseries}}
    59 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    60 \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    61 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}}
    62 
    63 % index macros
    64 \newcommand{\italic}[1]{\emph{\hyperpage{#1}}}
    65 \newcommand{\definition}[1]{\textbf{\hyperpage{#1}}}
    66 \newcommand{\see}[1]{\emph{see} #1}
    67 
    68 % Define some commands that produce formatted index entries suitable for cross-references.
    69 % ``\spec'' produces entries for specifications of entities.  ``\impl'' produces entries for their
    70 % implementations, and ``\use'' for their uses.
    71 
    72 %  \newcommand{\bold}[1]{{\bf #1}}
    73 %  \def\spec{\@bsphack\begingroup
    74 %             \def\protect##1{\string##1\space}\@sanitize
    75 %             \@wrxref{|bold}}
    76 \def\impl{\@bsphack\begingroup
    77           \def\protect##1{\string##1\space}\@sanitize
    78           \@wrxref{|definition}}
    79 \newcommand{\indexcode}[1]{{\lstinline$#1$}}
    80 \def\use{\@bsphack\begingroup
    81          \def\protect##1{\string##1\space}\@sanitize
    82          \@wrxref{|hyperpage}}
    83 \def\@wrxref#1#2{\let\thepage\relax
    84     \xdef\@gtempa{\write\@indexfile{\string
    85     \indexentry{#2@{\lstinline$#2$}#1}{\thepage}}}\endgroup\@gtempa
    86     \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}
    87 %\newcommand{\use}[1]{\index{#1@{\lstinline$#1$}}}
    88 %\newcommand{\impl}[1]{\index{\protect#1@{\lstinline$\protect#1$}|definition}}
    89 
    90 % inline text and lowercase index: \Index{inline and lowercase index text}
    91 % inline text and as-in index: \Index[as-is index text]{inline text}
    92 % inline text but index with different as-is text: \Index[index text]{inline text}
    93 \newcommand{\Index}{\@ifstar\@sIndex\@Index}
    94 \newcommand{\@Index}[2][\@empty]{\lowercase{\def\temp{#2}}#2\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi}
    95 \newcommand{\@sIndex}[2][\@empty]{#2\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi}
    96 
    97 \newcommand{\newtermFontInline}{\emph}
    98 \newcommand{\newterm}{\@ifstar\@snewterm\@newterm}
    99 \newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi}
    100 \newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi}
    101 \makeatother
    102 
    103 % blocks and titles
    104 \newenvironment{quote2}{%
    105         \list{}{\lstset{resetmargins=true}\leftmargin=\parindent\rightmargin\leftmargin}%
    106         \item\relax
    107 }{%
    108         \endlist
    109 }% quote2
    110 \newenvironment{rationale}{%
    111   \begin{quotation}\noindent$\Box$\enspace
    112 }{%
    113   \hfill\enspace$\Box$\end{quotation}
    114 }%
    115 \newcommand{\define}[1]{\emph{#1\/}\index{#1}}
    116 \newcommand{\rewrite}{\(\Rightarrow\)}
    117 \newcommand{\rewriterules}{\paragraph{Rewrite Rules}~\par\noindent}
    118 \newcommand{\examples}{\paragraph{Examples}~\par\noindent}
    119 \newcommand{\semantics}{\paragraph{Semantics}~\par\noindent}
    120 \newcommand{\constraints}{\paragraph{Constraints}~\par\noindent}
    121 \newcommand{\predefined}{\paragraph{Predefined Identifiers}~\par\noindent}
    122 
    123 % BNF macros
    124 \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]}
    125 \let\endsyntax=\endtrivlist
    126 \newcommand{\lhs}[1]{\par{\emph{#1:}}\index{#1@{\emph{#1}}|italic}}
    127 \newcommand{\rhs}{\hfil\break\hbox{\hskip1in}}
    128 \newcommand{\oldlhs}[1]{\emph{#1: \ldots}\index{#1@{\emph{#1}}|italic}}
    129 \newcommand{\nonterm}[1]{\emph{#1\/}\index{#1@{\emph{#1}}|italic}}
    130 \newcommand{\opt}{$_{opt}$\ }
    131 
    132 % adjust varioref package with default "section" and "page" titles, and optional title with faraway page numbers
    133 % \VRef{label} => Section 2.7, \VPageref{label} => page 17
    134 % \VRef[Figure]{label} => Figure 3.4, \VPageref{label} => page 17
    135 \renewcommand{\reftextfaceafter}{\unskip}
    136 \renewcommand{\reftextfacebefore}{\unskip}
    137 \renewcommand{\reftextafter}{\unskip}
    138 \renewcommand{\reftextbefore}{\unskip}
    139 \renewcommand{\reftextfaraway}[1]{\unskip, p.~\pageref{#1}}
    140 \renewcommand{\reftextpagerange}[2]{\unskip, pp.~\pageref{#1}--\pageref{#2}}
    141 \newcommand{\VRef}[2][Section]{\ifx#1\@empty\else{#1}\nobreakspace\fi\vref{#2}}
    142 \newcommand{\VPageref}[2][page]{\ifx#1\@empty\else{#1}\nobreakspace\fi\pageref{#2}}
    143 
    144 % Go programming language
    145 \lstdefinelanguage{Golang}%
    146   {morekeywords=[1]{package,import,func,type,struct,return,defer,panic, recover,select,var,const,iota,},%
    147    morekeywords=[2]{string,uint,uint8,uint16,uint32,uint64,int,int8,int16, int32,int64,
    148                 bool,float32,float64,complex64,complex128,byte,rune,uintptr, error,interface},%
    149    morekeywords=[3]{map,slice,make,new,nil,len,cap,copy,close,true,false, delete,append,real,imag,complex,chan,},%
    150    morekeywords=[4]{for,break,continue,range,goto,switch,case,fallthrough,if, else,default,},%
    151    morekeywords=[5]{Println,Printf,Error,},%
    152    sensitive=true,%
    153    morecomment=[l]{//},%
    154    morecomment=[s]{/*}{*/},%
    155    morestring=[b]',%
    156    morestring=[b]",%
    157    morestring=[s]{`}{`},%
    158 }
    159 
    160 % CFA based on ANSI C
    161 \lstdefinelanguage{CFA}[ANSI]{C}%
    162 {morekeywords={asm,_Alignas,_Alignof,_At,_Atomic,_Bool,catch,catchResume,choose,_Complex,trait,disable,dtype,enable,
    163         fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,lvalue,_Noreturn,otype,restrict,_Static_assert,
    164         _Thread_local,throw,throwResume,try,},
    165 }%
    166 
    167 \lstset{
    168 language=CFA,
    169 columns=flexible,
    170 basicstyle=\sf\relsize{-1},
    171 tabsize=4,
    172 xleftmargin=\parindent,
    173 escapechar=@,
    174 mathescape=true,
    175 keepspaces=true,
    176 showstringspaces=false,
    177 showlines=true,
    178 }%
    179 
    180 \makeatletter
    181 % replace/adjust listings characters that look bad in sanserif
    182 \lst@CCPutMacro
    183 \lst@ProcessOther{"2D}{\lst@ttfamily{-{}}{{\ttfamily\upshape -}}} % replace minus
    184 \lst@ProcessOther{"3C}{\lst@ttfamily{<}{\texttt{<}}} % replace less than
    185 \lst@ProcessOther{"3E}{\lst@ttfamily{<}{\texttt{>}}} % replace greater than
    186 \lst@ProcessOther{"5E}{\raisebox{0.4ex}{$\scriptstyle\land\,$}} % replace circumflex
    187 \lst@ProcessLetter{"5F}{\lst@ttfamily{\char95}{{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}}} % replace underscore
    188 \lst@ProcessOther{"7E}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}} % replace tilde
    189 %\lst@ProcessOther{"7E}{\raisebox{-.4ex}[1ex][0pt]{\textasciitilde}} % lower tilde
    190 \@empty\z@\@empty
    191 \makeatother
    192 
    193 \setcounter{secnumdepth}{3}     % number subsubsections
    194 \setcounter{tocdepth}{3}                % subsubsections in table of contents
     62\setcounter{secnumdepth}{3}                             % number subsubsections
     63\setcounter{tocdepth}{3}                                % subsubsections in table of contents
    19564\makeindex
    19665
     
    19968\begin{document}
    20069\pagestyle{headings}
    201 \linenumbers                                    % comment out to turn off line numbering
     70\linenumbers                                            % comment out to turn off line numbering
    20271
    20372\title{\Huge
     
    21382}% author
    21483\date{
    215 DRAFT\\\today
     84DRAFT \\
     85\today
    21686}% date
    21787
     
    241111
    242112\CFA\footnote{Pronounced ``C-for-all'', and written \CFA, CFA, or \CFL.} is a modern general-purpose programming-language, designed an as evolutionary step forward from the C programming language.
    243 The syntax of the \CFA language builds from that of C, and should look immediately familiar to C programmers.
     113The syntax of the \CFA language builds from C, and should look immediately familiar to C programmers.
    244114% Any language feature that is not described here can be assumed to be using the standard C11 syntax.
    245 \CFA has added many modern programming-language features, which directly leads to increased safety and productivity, while maintaining interoperability with existing C programs, and maintaining C-like performance.
     115\CFA adds many modern programming-language features, which directly leads to increased safety and productivity, while maintaining interoperability with existing C programs and achieving C performance.
    246116Like C, \CFA is a statically typed, procedural language with a low-overhead runtime, meaning there is no global garbage-collection.
    247117The primary new features include parametric-polymorphism routines and types, exceptions, concurrency, and modules.
     
    254124New programs can be written in \CFA using a combination of C and \CFA features.
    255125\CC had a similar goal 30 years ago, but has struggled over the intervening time to incorporate modern programming-language features because of early design choices.
    256 \CFA has 30 years of hindsight and a much cleaner starting point than \CC.
     126\CFA has 30 years of hindsight and clean starting point.
    257127
    258128Like \CC, there may be both an old and new ways to achieve the same effect.
     
    279149\end{quote2}
    280150Both programs output the same result.
    281 While the \CFA I/O looks similar to the \CC style of output, there are several important differences, such as automatic spacing between variables as in Python (see also~\VRef{s:IOLibrary}).
     151While the \CFA I/O looks similar to the \CC output style, there are several important differences, such as automatic spacing between variables as in Python (see also~\VRef{s:IOLibrary}).
    282152
    283153This document is a reference manual for the \CFA programming language, targeted at \CFA programmers.
    284 Implementers may also refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
     154Implementers may refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
    285155In its current state, this document covers the intended core features of the language.
    286156Changes to the syntax and additional features are expected to be included in later revisions.
     
    294164The original \CFA project~\cite{Ditchfield92} extended the C type system with parametric polymorphism and overloading, as opposed to the \CC approach of object-oriented extensions to the C type-system.
    295165A first implementation of the core Cforall language was created~\cite{Bilson03,Esteves04}, but at the time there was little interesting in extending C, so work did not continue.
    296 As the saying goes, ``What goes around, comes around'', and there is now renewed interest in the C programming language, so the \CFA project has been restarted.
    297 
    298 
    299 \section{Motivation: Why fix C?}
     166As the saying goes, ``What goes around, comes around'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted.
     167
     168
     169\section{Why fix C?}
    300170
    301171Even with all its problems, C is a very popular programming language because it allows writing software at virtually any level in a computer system without restriction.
     
    314184Java~\cite{Java8}, Go~\cite{Go}, Rust~\cite{Rust} and D~\cite{D} are examples of the revolutionary approach for modernizing C/\CC, resulting in a new language rather than an extension of the descendent.
    315185These languages have different syntax and semantics from C, and do not interoperate directly with C, largely because of garbage collection.
    316 As a result, there is a significant learning curve to move to these languages, and C legacy-code must be complete rewritten.
     186As a result, there is a significant learning curve to move to these languages, and C legacy-code must be rewritten.
    317187These costs can be prohibitive for many companies with a large software base in C/\CC, and many programmers that require retraining to a new programming language.
    318188
     
    331201This feature allows users of \CFA to take advantage of the existing panoply of C libraries from inside their \CFA code.
    332202In fact, one of the biggest issues for any new programming language is establishing a minimum level of library code to support a large body of activities.
    333 Programming-language developers often state that adequate library support costs many times more than designing and implementing the language itself.
     203Programming-language developers often state that adequate library support takes more work than designing and implementing the language itself.
    334204Like \CC, \CFA starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at very low cost.
    335205
     
    338208Whereas, \CFA wraps each of these routines into one with the common name \lstinline@abs@.
    339209\begin{lstlisting}
     210char abs( char );
    340211extern "C" {
    341 #include <stdlib.h>                     // provide C prototype for integer "abs" routine
     212int abs( int );                         // use default C routine for int
    342213} // extern "C"
    343 
    344 char abs( char );
    345 long int abs( long int );       // @{\CFA}@ overload name "abs" for other types
     214long int abs( long int );
    346215long long int abs( long long int );
    347216float abs( float );
     
    360229The name ``\lstinline@abs@'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value.
    361230Hence, knowing the name \lstinline@abs@ should be sufficient to apply it to any type where it is applicable.
    362 The time savings and safety of using one name uniformly versus @N@ unique names should not be underestimated.
    363 
    364 
    365 \section{Compiling \CFA}
     231The time savings and safety of using one name uniformly versus $N$ unique names should not be underestimated.
     232
     233
     234\section[Compiling CFA Program]{Compiling \CFA Program}
    366235
    367236The command \lstinline@cfa@ is used to compile \CFA program(s).
    368 This command works like the GNU \lstinline@gcc@ command, e.g.:
    369 \begin{lstlisting}
    370 cfa [ gcc-options ] C/@{\CFA}@-files [ assembler/loader-files ]
    371 \end{lstlisting}
    372 The following additional option is available:
     237This command works like the GNU \lstinline@gcc@\index{gcc} command, e.g.:
     238\begin{lstlisting}
     239cfa [ gcc-options ] C/§\CFA§-files [ assembler/loader-files ]
     240\end{lstlisting}
     241\indexc{cfa}\index{compilation!cfa@\lstinline$cfa$}
     242By default, \CFA programs having the following \lstinline@gcc@ flags turned on:
    373243\begin{description}
    374 \item
    375 \hspace*{-4pt}\lstinline@-CFA@
     244\item\hspace*{-4pt}\Indexc{-std=gnu99}\index{compilation option!-std=gnu99@{\lstinline$-std=gnu99$}}
     245The 1999 C standard plus GNU extensions.
     246\item\hspace*{-4pt}\Indexc{-fgnu89-¶inline¶}\index{compilation option!-fgnu89-inline@{\lstinline$-fgnu89-¶inline¶$}}
     247Use the traditional GNU semantics for inline routines in C99 mode.
     248\end{description}
     249The following new \CFA option is available:
     250\begin{description}
     251\item\hspace*{-4pt}\Indexc{-CFA}\index{compilation option!-CFA@{\lstinline$-CFA$}}
    376252Only the C preprocessor and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator.
    377253\end{description}
    378254
     255The following preprocessor variables are available:
     256\begin{description}
     257\item\hspace*{-4pt}\Indexc{__CFA__}\index{preprocessor variables!__CFA__@{\lstinline$__CFA__$}}
     258is always available during preprocessing and its value is the current major \Index{version number} of \CFA.\footnote{
     259The C preprocessor allows only integer values in a preprocessor variable so a value like ``\Version'' is not allowed.
     260Hence, the need to have three variables for the major, minor and patch version number.}
     261
     262\item\hspace*{-4pt}\Indexc{__CFA_MINOR__}\index{preprocessor variables!__CFA_MINOR__@{\lstinline$__CFA_MINOR__$}}
     263is always available during preprocessing and its value is the current minor \Index{version number} of \CFA.
     264
     265\item\hspace*{-4pt}\Indexc{__CFA_PATCH__}\index{preprocessor variables!__CFA_PATCH__@\lstinline$__CFA_PATCH__$}
     266is always available during preprocessing and its value is the current patch \Index{version number} of \CFA.
     267
     268\item\hspace*{-4pt}\Indexc{__CFORALL__}\index{preprocessor variables!__CFORALL__@\lstinline$__CFORALL__$}
     269is always available during preprocessing and it has no value.
     270\end{description}
     271
     272These preprocessor variables allow conditional compilation of programs that must work differently in these situations.
     273For example, to toggle between C and \CFA extensions, using the following:
     274\begin{lstlisting}
     275#ifndef __CFORALL__
     276#include <stdio.h>                      // C header file
     277#else
     278#include <fstream>                      // §\CFA{}§ header file
     279#endif
     280\end{lstlisting}
     281which conditionally includes the correct header file, if the program is compiled using \lstinline@gcc@ or \lstinline@cfa@.
     282
    379283
    380284\section{Underscores in Constants}
     
    382286Numeric constants are extended to allow \Index{underscore}s within constants\index{constant!underscore}, e.g.:
    383287\begin{lstlisting}
    384 2_147_483_648;                          // decimal constant
     2882®_®147®_®483®_®648;                            // decimal constant
    38528956_ul;                                          // decimal unsigned long constant
    3862900_377;                                          // octal constant
     
    408312the type suffixes \lstinline@U@, \lstinline@L@, etc. may start with an underscore \lstinline@1_U@, \lstinline@1_ll@ or \lstinline@1.0E10_f@.
    409313\end{enumerate}
    410 It is significantly easier to read and type long constants when they are broken up into smaller groupings (most cultures use comma or period among digits for the same purpose).
     314It 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).
    411315This extension is backwards compatible, matches with the use of underscore in variable names, and appears in Ada and Java.
    412316
     
    417321C declaration syntax is notoriously confusing and error prone.
    418322For example, many C programmers are confused by a declaration as simple as:
    419 \begin{lstlisting}
    420 int *x[ 10 ]
    421 \end{lstlisting}
    422 Is this a pointer to an array of 10 integers or an array of 10 pointers to integers?
     323\begin{quote2}
     324\begin{tabular}{@{}ll@{}}
     325\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
     326int *x[ 5 ]
     327\end{lstlisting}
     328&
     329\raisebox{-0.75\totalheight}{\input{Cdecl}}
     330\end{tabular}
     331\end{quote2}
     332Is this an array of 5 pointers to integers or a pointer to an array of 5 integers?
    423333Another example of confusion results from the fact that a routine name and its parameters are embedded within the return type, mimicking the way the return value is used at the routine's call site.
    424334For example, a routine returning a pointer to an array of integers is defined and used in the following way:
    425335\begin{lstlisting}
    426 int (*f())[ 10 ] {...};
    427 ... (*f())[ 3 ] += 1;           // definition mimics usage
     336int (*f())[ 5 ] {...};  // definition mimics usage
     337... (*f())[ 3 ] += 1;
    428338\end{lstlisting}
    429339Essentially, the return type is wrapped around the routine name in successive layers (like an onion).
     
    434344The only exception is bit field specification, which always appear to the right of the base type.
    435345C and the new \CFA declarations may appear together in the same program block, but cannot be mixed within a specific declaration.
    436 Unsupported are K\&R C declarations where the base type defaults to \lstinline@int@, if no type is specified\footnote{
    437 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}},
    438 e.g.:
    439 \begin{lstlisting}
    440 x;                                      // int x
    441 *y;                                     // int *y
    442 f( p1, p2 );            // int f( int p1, int p2 );
    443 f( p1, p2 ) {}          // int f( int p1, int p2 ) {}
    444 \end{lstlisting}
    445346
    446347In \CFA declarations, the same tokens are used as in C: the character \lstinline@*@ is used to indicate a pointer, square brackets \lstinline@[@\,\lstinline@]@ are used to represent an array, and parentheses \lstinline@()@ are used to indicate a routine parameter.
     
    451352\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    452353\begin{lstlisting}
    453 * int x, y;
     354®* int x, y;®
    454355\end{lstlisting}
    455356&
     
    464365\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    465366\begin{lstlisting}
    466 [ 10 ] int z;
    467 [ 10 ] * char w;
    468 * [ 10 ] double v;
     367[ 5 ] int z;
     368[ 5 ] * char w;
     369* [ 5 ] double v;
    469370struct s {
    470 int f0:3;
     371        int f0:3;
    471372        * int f1;
    472         [ 10 ] * int f2;
     373        [ 5 ] * int f2;
    473374};
    474375\end{lstlisting}
    475376&
    476377\begin{lstlisting}
    477 int z[ 10 ];
    478 char *w[ 10 ];
    479 double (*v)[ 10 ];
     378int z[ 5 ];
     379char *w[ 5 ];
     380double (*v)[ 5 ];
    480381struct s {
    481382        int f0:3;
    482383        int *f1;
    483         int *f2[ 10 ]
     384        int *f2[ 5 ]
    484385};
    485386\end{lstlisting}
    486387&
    487388\begin{lstlisting}
    488 // array of 10 integers
    489 // array of 10 pointers to char
    490 // pointer to array of 10 doubles
     389// array of 5 integers
     390// array of 5 pointers to char
     391// pointer to array of 5 doubles
    491392
    492393// common bit field syntax
     
    497398\end{tabular}
    498399\end{quote2}
    499 
    500 As stated above, the two styles of declaration may appear together in the same block.
    501 Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.
    502 Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX systems.
    503 In general, mixing declaration styles in a routine or even a translation unit is not recommended, as it makes a program more difficult to read.
    504 Therefore, it is suggested that an entire translation unit be written in one declaration style or the other.
    505400
    506401All type qualifiers, i.e., \lstinline@const@ and \lstinline@volatile@, are used in the normal way with the new declarations but appear left to right, e.g.:
     
    510405\begin{lstlisting}
    511406const * const int x;
    512 const * [ 10 ] const int y;
     407const * [ 5 ] const int y;
    513408\end{lstlisting}
    514409&
    515410\begin{lstlisting}
    516411int const * const x;
    517 const int (* const y)[ 10 ]
     412const int (* const y)[ 5 ]
    518413\end{lstlisting}
    519414&
    520415\begin{lstlisting}
    521416// const pointer to const integer
    522 // const pointer to array of 10 const integers
     417// const pointer to array of 5 const integers
    523418\end{lstlisting}
    524419\end{tabular}
     
    530425\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    531426\begin{lstlisting}
    532 extern [ 10 ] int x;
     427extern [ 5 ] int x;
    533428static * const int y;
    534429\end{lstlisting}
    535430&
    536431\begin{lstlisting}
    537 int extern x[ 10 ];
     432int extern x[ 5 ];
    538433const int static *y;
    539434\end{lstlisting}
    540435&
    541436\begin{lstlisting}
    542 // externally visible array of 10 integers
     437// externally visible array of 5 integers
    543438// internally visible pointer to constant int
    544439\end{lstlisting}
    545440\end{tabular}
    546441\end{quote2}
     442
     443Unsupported are K\&R C declarations where the base type defaults to \lstinline@int@, if no type is specified\footnote{
     444At 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}},
     445e.g.:
     446\begin{lstlisting}
     447x;                                              // int x
     448*y;                                             // int *y
     449f( p1, p2 );                    // int f( int p1, int p2 );
     450f( p1, p2 ) {}                  // int f( int p1, int p2 ) {}
     451\end{lstlisting}
     452
     453As stated above, the two styles of declaration may appear together in the same block.
     454Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.
     455Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX systems.
    547456
    548457
     
    555464\begin{lstlisting}
    556465y = (* int)x;
    557 i = sizeof([ 10 ] * int);
     466i = sizeof([ 5 ] * int);
    558467\end{lstlisting}
    559468&
    560469\begin{lstlisting}
    561470y = (int *)x;
    562 i = sizeof(int *[ 10 ]);
     471i = sizeof(int *[ 5 ]);
    563472\end{lstlisting}
    564473\end{tabular}
     
    571480The point of the new syntax is to allow returning multiple values from a routine~\cite{CLU,Galletly96}, e.g.:
    572481\begin{lstlisting}
    573 [ int o1, int o2, char o3 ] f( int i1, char i2, char i3 ) {
    574         @\emph{routine body}@
     482®[ int o1, int o2, char o3 ]® f( int i1, char i2, char i3 ) {
     483        §\emph{routine body}§
    575484}
    576485\end{lstlisting}
     
    583492Declaration qualifiers can only appear at the start of a routine definition, e.g.:
    584493\begin{lstlisting}
    585 extern [ int x ] g( int y ) {}
     494extern [ int x ] g( int y ) {§\,§}
    586495\end{lstlisting}
    587496Lastly, if there are no output parameters or input parameters, the brackets and/or parentheses must still be specified;
    588497in 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:
    589498\begin{lstlisting}
    590 [ ] g();                                        // no input or output parameters
     499[§\,§] g();                                             // no input or output parameters
    591500[ void ] g( void );                     // no input or output parameters
    592501\end{lstlisting}
     
    600509\CFA style declarations cannot be used to declare parameters for K\&R style routine definitions because of the following ambiguity:
    601510\begin{lstlisting}
    602 int (*f(x))[ 10 ] int x; {}
    603 \end{lstlisting}
    604 The string ``\lstinline@int (*f(x))[ 10 ]@'' declares a K\&R style routine of type returning a pointer to an array of 10 integers, while the string ``\lstinline@[ 10 ] int x@'' declares a \CFA style parameter x of type array of 10 integers.
     511int (*f(x))[ 5 ] int x; {}
     512\end{lstlisting}
     513The string ``\lstinline@int (*f(x))[ 5 ]@'' declares a K\&R style routine of type returning a pointer to an array of 5 integers, while the string ``\lstinline@[ 5 ] int x@'' declares a \CFA style parameter x of type array of 5 integers.
    605514Since the strings overlap starting with the open bracket, \lstinline@[@, there is an ambiguous interpretation for the string.
    606515As well, \CFA-style declarations cannot be used to declare parameters for C-style routine-definitions because of the following ambiguity:
     
    621530\begin{lstlisting}
    622531#define ptoa( n, d ) int (*n)[ d ]
    623 int f( ptoa(p,10) ) ...         // expands to int f( int (*p)[ 10 ] )
    624 [ int ] f( ptoa(p,10) ) ...     // expands to [ int ] f( int (*p)[ 10 ] )
     532int f( ptoa(p,5) ) ...          // expands to int f( int (*p)[ 5 ] )
     533[ int ] f( ptoa(p,5) ) ...      // expands to [ int ] f( int (*p)[ 5 ] )
    625534\end{lstlisting}
    626535Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    639548Because the value in the return variable is automatically returned when a \CFA routine terminates, the \lstinline@return@ statement \emph{does not} contain an expression, as in:
    640549\begin{lstlisting}
    641 [ int x ] f() {
     550®[ int x ]® f() {
    642551        ... x = 0; ... x = y; ...
    643         return; // implicitly return x
     552        ®return;® // implicitly return x
    644553}
    645554\end{lstlisting}
     
    697606for example, the following is incorrect:
    698607\begin{lstlisting}
    699 * [ int x ] f () fp;            // routine name ``f'' is not allowed
     608* [ int x ] f () fp;            // routine name "f" is not allowed
    700609\end{lstlisting}
    701610
     
    703612\section{Named and Default Arguments}
    704613
    705 Named and default arguments~\cite{Hardgrave76}.\footnote{
     614Named and default arguments~\cite{Hardgrave76}\footnote{
    706615Francez~\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.}
    707616are two mechanisms to simplify routine call.
     
    864773\subsection{Type Nesting}
    865774
    866 C allows \Index{type nesting}, but the nested types are hoisted\index{type!hoisting} (refactored) into the enclosing scope.
     775\CFA allows \Index{type nesting}, and type qualification of the nested types, where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
    867776\begin{quote2}
    868777\begin{tabular}{@{}l@{\hspace{30pt}}l|l@{}}
     
    919828
    920829int fred() {
    921         s.t.c = S.R;
    922         struct S.T t = { S.R, 1, 2 };
    923         enum S.C c;
    924         union S.T.U u;
     830        s.t.c = ®S.®R;  // type qualification
     831        struct ®S.®T t = { ®S.®R, 1, 2 };
     832        enum ®S.®C c;
     833        union ®S.T.®U u;
    925834}
    926835\end{lstlisting}
    927836\end{tabular}
    928837\end{quote2}
    929 
    930 \CFA is C \emph{incompatible} on this issue, and provides semantics similar to \CC.
    931 Nested types are not hoisted and can be referenced using the field selection operator ``\lstinline@.@'', unlike the \CC scope-resolution operator ``\lstinline@::@''.
    932 Given that nested types in C are equivalent to not using them, i.e., they are essentially useless, it is unlikely there are any realistic usages that break because of this incompatibility.
     838In the left example in C, types \lstinline@C@, \lstinline@U@ and \lstinline@T@ are implicitly hoisted outside of type \lstinline@S@ into the containing block scope.
     839In the right example in \CFA, the types are not hoisted and accessed using the field-selection operator ``\lstinline@.@'' for type qualification, as does Java, rather than the \CC type-selection operator ``\lstinline@::@''.
    933840
    934841
     
    943850which can be used to sort in ascending and descending order by locally redefining the less-than operator into greater-than.
    944851\begin{lstlisting}
    945 const unsigned int size = 10;
    946 int a[size];
    947 
    948 qsort( a, size );               // ascending order using built in ?<?
    949 {                                               // descending order by local redefinition
    950         int ?<?( int a, int b ) { return a > b; } // nested routine
    951         qsort( a, size );
    952 }
    953 \end{lstlisting}
    954 
    955 
    956 \section{Incompatible}
    957 
    958 The following incompatibles exist between C and \CFA, and are similar to Annex C for \CC~\cite{ANSI14:C++}.
    959 
    960 \begin{enumerate}
    961 \item
    962 Change type of character literal \lstinline@int@ to \lstinline@char@.
    963 This change allows overloading differentiation argument type matching, e.g.:
    964 \begin{lstlisting}
    965 int function( int i );
    966 int function( char c );
    967 function( 'x' );
    968 \end{lstlisting}
    969 It is preferable that this call match the second version of function rather than the first. \\
    970 Effect on original feature: Change to semantics of well-defined feature. ISO C programs which depend on
    971 \begin{lstlisting}
    972 sizeof('x') == sizeof(int)
    973 \end{lstlisting}
    974 will not work the same as C++ programs. \\
    975 Difficulty of converting: Simple. \\
    976 How widely used: Programs which depend upon sizeof('x') are probably rare.
    977 
    978 \item
    979 Change: String literals made \lstinline@const@ \\
    980 The type of a string literal is changed from \lstinline@array of char@ to \lstinline@array of const char@.
    981 The type of a wide string literal is changed from \lstinline@array of wchar_t@ to \lstinline@array of const wchar_t@. \\
    982 Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument.
    983 Effect on original feature: Change to semantics of well-defined feature. \\
    984 Difficulty of converting: Simple syntactic transformation, because string literals can be converted to \lstinline@char*;@ (4.2).
    985 The most common cases are handled by a new but deprecated standard conversion:
    986 \begin{lstlisting}
    987 char* p = "abc"; // valid in C, deprecated in C++
    988 char* q = expr ? "abc" : "de"; // valid in C, invalid in C++
    989 \end{lstlisting}
    990 How widely used: Programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are probably rare.
    991 
    992 \item
    993 Change: C++ does not have \emph{tentative definitions} as in C.
    994 E.g., at file scope,
    995 \begin{lstlisting}
    996 int i;
    997 int i;
    998 \end{lstlisting}
    999 is valid in C, invalid in C++.
    1000 This makes it impossible to define mutually referential file-local static
    1001 objects, if initializers are restricted to the syntactic forms of C. For example,
    1002 \begin{lstlisting}
    1003 struct X { int i; struct X *next; };
    1004 static struct X a;
    1005 static struct X b = { 0, &a };
    1006 static struct X a = { 1, &b };
    1007 \end{lstlisting}
    1008 Rationale: This avoids having different initialization rules for builtin types and userdefined types.
    1009 Effect on original feature: Deletion of semantically welldefined feature. \\
    1010 Difficulty of converting: Semantic transformation.
    1011 In C++, the initializer for one of a set of mutuallyreferential filelocal static objects must invoke a function call to achieve the initialization.
    1012 How widely used: Seldom.
    1013 
    1014 \item
    1015 Change: A struct is a scope in C++, not in C
    1016 Rationale: Class scope is crucial to C++, and a struct is a class.
    1017 Effect on original feature: Change to semantics of well-defined feature.
    1018 Difficulty of converting: Semantic transformation.
    1019 How widely used: C programs use struct extremely frequently, but the change is only noticeable when
    1020 struct, enumeration, or enumerator names are referred to outside the struct. The latter is probably
    1021 rare.
    1022 
    1023 \item
    1024 Change: In C++, the name of a nested class is local to its enclosing class.
    1025 In C the name of the nested class belongs to the same scope as the name of the outermost enclosing class
    1026 Example:
    1027 \begin{lstlisting}
    1028 struct X {
    1029 struct Y { /* ... */ } y;
    1030 };
    1031 struct Y yy; // valid C, invalid C++
    1032 \end{lstlisting}
    1033 Rationale: C++ classes have member functions which require that classes establish scopes. The C rule
    1034 would leave classes as an incomplete scope mechanism which would prevent C++ programmers from maintaining
    1035 locality within a class. A coherent set of scope rules for C++ based on the C rule would be very
    1036 complicated and C++ programmers would be unable to predict reliably the meanings of nontrivial examples
    1037 involving nested or local functions.
    1038 Effect on original feature: Change of semantics of welldefined
    1039 feature.
    1040 Difficulty of converting: Semantic transformation. To make the struct type name visible in the scope of
    1041 the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing
    1042 struct is defined. Example:
    1043 \begin{lstlisting}
    1044 struct Y; // struct Y and struct X are at the same scope
    1045 struct X {
    1046 struct Y { /* ... */ } y;
    1047 };
    1048 \end{lstlisting}
    1049 All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of
    1050 the enclosing struct could be exported to the scope of the enclosing struct. Note: this is a consequence of
    1051 the difference in scope rules, which is documented in 3.3.
    1052 How widely used: Seldom.
    1053 \end{enumerate}
     852const unsigned int size = 5;
     853int ia[size];
     854...                                             // assign values to array ia
     855qsort( ia, size );              // sort ascending order using builtin ?<?
     856{
     857        ®int ?<?( int x, int y ) { return x > y; }® // nested routine
     858        qsort( ia, size );      // sort descending order by local redefinition
     859}
     860\end{lstlisting}
     861
     862Nested routines are not first-class, meaning a nested routine cannot be returned if it has references to variables in its enclosing blocks;
     863the only exception is references to the external block of the translation unit, as these variables persist for the duration of the program.
     864The following program in undefined in \CFA (and \lstinline@gcc@\index{gcc})
     865\begin{lstlisting}
     866[* [int]( int )] foo() {                // int (*foo())( int )
     867        int ®i® = 7;
     868        int bar( int p ) {
     869                ®i® += 1;                                       // dependent on local variable
     870                sout | ®i® | endl;
     871        }
     872        return bar;                                     // undefined because of local dependence
     873}
     874int main() {
     875        * [int](int) fp = foo();        // int (*fp)(int)
     876    sout | fp( 3 ) | endl;
     877}
     878\end{lstlisting}
     879because
     880
     881Currently, there are no \Index{lambda} expressions, i.e., unnamed routines because routine names are very important to properly select the correct routine.
    1054882
    1055883
     
    1061889The general syntax of a tuple is:
    1062890\begin{lstlisting}
    1063 [ $\emph{exprlist}$ ]
     891[ §\emph{exprlist}§ ]
    1064892\end{lstlisting}
    1065893where \lstinline@$\emph{exprlist}$@ is a list of one or more expressions separated by commas.
     
    1081909The general syntax of a tuple type is:
    1082910\begin{lstlisting}
    1083 [ @\emph{typelist}@ ]
     911[ §\emph{typelist}§ ]
    1084912\end{lstlisting}
    1085913where \lstinline@$\emph{typelist}$@ is a list of one or more legal \CFA or C type specifications separated by commas, which may include other tuple type specifications.
     
    1089917[ double, double, double ]
    1090918[ * int, int * ]                // mix of CFA and ANSI
    1091 [ * [ 10 ] int, * * char, * [ [ int, int ] ] (int, int) ]
     919[ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    1092920\end{lstlisting}
    1093921Like tuples, tuple types may be nested, such as \lstinline@[ [ int, int ], int ]@, which is a 2-element tuple type whose first element is itself a tuple type.
     
    11851013First the right-hand tuple is flattened and then the values are assigned individually.
    11861014Flattening is also performed on tuple types.
    1187 For example, the type \lstinline@[ int, [ int, int ], int ]@ can be coerced, using flattening, into the type lstinline@[ int, int, int, int ]@.
     1015For example, the type \lstinline@[ int, [ int, int ], int ]@ can be coerced, using flattening, into the type \lstinline@[ int, int, int, int ]@.
    11881016
    11891017A \newterm{structuring coercion} is the opposite of flattening;
     
    12111039Mass assignment has the following form:
    12121040\begin{lstlisting}
    1213 [ @\emph{lvalue}@, ..., @\emph{lvalue}@ ] = @\emph{expr}@;
    1214 \end{lstlisting}
    1215 The left-hand side is a tuple of \lstinline@$\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.
     1041[ §\emph{lvalue}§, ..., §\emph{lvalue}§ ] = §\emph{expr}§;
     1042\end{lstlisting}
     1043The 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.
    12161044\lstinline@$\emph{expr}$@ is any standard arithmetic expression.
    12171045Clearly, the types of the entities being assigned must be type compatible with the value of the expression.
     
    12501078Multiple assignment has the following form:
    12511079\begin{lstlisting}
    1252 [ @\emph{lvalue}@, . . ., @\emph{lvalue}@ ] = [ @\emph{expr}@, . . ., @\emph{expr}@ ];
    1253 \end{lstlisting}
    1254 The left-hand side is a tuple of \lstinline@$\emph{lvalues}$@, and the right-hand side is a tuple of \lstinline@$\emph{expr}$@s.
    1255 Each \lstinline@$\emph{expr}$@ appearing on the righthand side of a multiple assignment statement is assigned to the corresponding \lstinline@$\emph{lvalues}$@ on the left-hand side of the statement using parallel semantics for each assignment.
     1080[ §\emph{lvalue}§, . . ., §\emph{lvalue}§ ] = [ §\emph{expr}§, . . ., §\emph{expr}§ ];
     1081\end{lstlisting}
     1082The left-hand side is a tuple of \emph{lvalues}, and the right-hand side is a tuple of \emph{expr}s.
     1083Each \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.
    12561084An example of multiple assignment is:
    12571085\begin{lstlisting}
     
    12901118Cascade assignment has the following form:
    12911119\begin{lstlisting}
    1292 @\emph{tuple}@ = @\emph{tuple}@ = ... = @\emph{tuple}@;
     1120§\emph{tuple}§ = §\emph{tuple}§ = ... = §\emph{tuple}§;
    12931121\end{lstlisting}
    12941122and it has the same parallel semantics as for mass and multiple assignment.
     
    13081136Its general form is:
    13091137\begin{lstlisting}
    1310 @\emph{expr}@ . [ @\emph{fieldlist}@ ]
    1311 @\emph{expr}@ -> [ @\emph{fieldlist}@ ]
    1312 \end{lstlisting}
    1313 \lstinline@$\emph{expr}$@ is any expression yielding a value of type record, e.g., \lstinline@struct@, \lstinline@union@.
    1314 Each element of \lstinline@$\emph{ fieldlist}$@ is an element of the record specified by \lstinline@$\emph{expr}$@.
     1138§\emph{expr}§ . [ §\emph{fieldlist}§ ]
     1139§\emph{expr}§ -> [ §\emph{fieldlist}§ ]
     1140\end{lstlisting}
     1141\emph{expr} is any expression yielding a value of type record, e.g., \lstinline@struct@, \lstinline@union@.
     1142Each element of \emph{ fieldlist} is an element of the record specified by \emph{expr}.
    13151143A record-field tuple may be used anywhere a tuple can be used. An example of the use of a record-field tuple is
    13161144the following:
     
    13521180\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    13531181\begin{lstlisting}
    1354 L1: for ( ... ) {
    1355         L2: for ( ... ) {
    1356                 L3: for ( ... ) {
    1357                         ... break L1; ...
    1358                         ... break L2; ...
    1359                         ... break L3; // or break
     1182®L1:® for ( ... ) {
     1183        ®L2:® for ( ... ) {
     1184                ®L3:® for ( ... ) {
     1185                        ... break ®L1®; ...
     1186                        ... break ®L2®; ...
     1187                        ... break ®L3®; // or break
    13601188                }
    13611189        }
     
    13821210\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    13831211\begin{lstlisting}
    1384 L1: for ( ... ) {
    1385         L2: for ( ... ) {
    1386                 L3: for ( ... ) {
    1387                         ... continue L1; ...
    1388                         ... continue L2; ...
    1389                         ... continue L3; ...
     1212®L1®: for ( ... ) {
     1213        ®L2®: for ( ... ) {
     1214                ®L3®: for ( ... ) {
     1215                        ... continue ®L1®; ...
     1216                        ... continue ®L2®; ...
     1217                        ... continue ®L3®; ...
    13901218
    13911219                }
     
    16231451\begin{lstlisting}
    16241452switch ( i ) {
    1625   case 1, 3, 5:
     1453  ®case 1, 3, 5®:
    16261454        ...
    1627   case 2, 4, 6:
     1455  ®case 2, 4, 6®:
    16281456        ...
    16291457}
     
    16341462  case 1: case 3 : case 5:
    16351463        ...
    1636   case 2: case 4 : case 6: /* even values */
     1464  case 2: case 4 : case 6:
    16371465        ...
    16381466}
     
    16551483\begin{lstlisting}
    16561484switch ( i ) {
    1657   case 1~5
     1485  ®case 1~5:®
    16581486        ...
    1659   case 10~15
     1487  ®case 10~15:®
    16601488        ...
    16611489}
     
    16721500&
    16731501\begin{lstlisting}
     1502
    16741503// 1, 2, 3, 4, 5
    16751504
     
    21681997
    21691998
    2170 \section{Generics }
     1999\section{Auto Type-Inferencing}
     2000
     2001Auto type-inferencing occurs in a declaration where a variable's type is inferred from its initialization expression type.
     2002\begin{quote2}
     2003\begin{tabular}{@{}l@{\hspace{30pt}}ll@{}}
     2004\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CC}}        & \multicolumn{1}{c}{\lstinline@gcc@}\index{gcc} \\
     2005\begin{lstlisting}
     2006
     2007auto j = 3.0 * 4;
     2008int i;
     2009auto k = i;
     2010\end{lstlisting}
     2011&
     2012\begin{lstlisting}
     2013#define expr 3.0 * i
     2014typeof(expr) j = expr;
     2015int i;
     2016typeof(i) k = i;
     2017\end{lstlisting}
     2018&
     2019\begin{lstlisting}
     2020
     2021// use type of initialization expression
     2022
     2023// use type of primary variable
     2024\end{lstlisting}
     2025\end{tabular}
     2026\end{quote2}
     2027The two important capabilities are:
     2028\begin{itemize}
     2029\item
     2030preventing having to determine or write out long generic types,
     2031\item
     2032ensure secondary variables, related to a primary variable, always have the same type.
     2033\end{itemize}
     2034
     2035In \CFA, \lstinline@typedef@ provides a mechanism to alias long type names with short ones, both globally and locally, but not eliminate the use of the short name.
     2036\lstinline@gcc@ provides \lstinline@typeof@ to declare a secondary variable from a primary variable.
     2037\CFA also relies heavily on the specification of the left-hand side of assignment for type inferencing, so in many cases it is crucial to specify the type of the left-hand side to select the correct type of the right-hand expression.
     2038Only for overloaded routines with the same return type is variable type-inferencing possible.
     2039Finally, \lstinline@auto@ presents the programming problem of tracking down a type when the type is actually needed.
     2040For example, given
     2041\begin{lstlisting}
     2042auto j = ®...®
     2043\end{lstlisting}
     2044and the need to write a routine to compute using \lstinline@j@
     2045\begin{lstlisting}
     2046void rtn( ®...® parm );
     2047rtn( j );
     2048\end{lstlisting}
     2049A programmer must work backwards to determine the type of \lstinline@j@'s initialization expression, reconstructing the possibly long generic type-name.
     2050In this situation, having the type name or a short alias is very useful.
     2051
     2052There is also the conundrum in type inferencing of when to \emph{\Index{brand}} a type.
     2053That is, when is the type of the variable more important than the type of its initialization expression.
     2054For example, if a change is made in an initialization expression, it can cause hundreds or thousands of cascading type changes and/or errors.
     2055At some point, a programmer wants the type of the variable to remain constant and the expression to be in error when it changes.
     2056
     2057Given \lstinline@typedef@ and \lstinline@typeof@ in \CFA, and the strong need to use the type of left-hand side in inferencing, auto type-inferencing is not supported at this time.
     2058Should a significant need arise, this feature can be revisited.
     2059
     2060
     2061\section{Generics}
    21712062
    21722063\CFA supports parametric polymorphism to allow users to define generic functions and types.
     
    23682259
    23692260        try {
    2370         throw 13;
     2261                throw 13;
    23712262        }
    23722263        catch(int e) {
    2373         printf(.caught an exception: %d\n., e);
     2264                printf(.caught an exception: %d\n., e);
    23742265        }
    23752266\end{lstlisting}
     
    24572348
    24582349
    2459 \section{I/O Library}
    2460 \label{s:IOLibrary}
    2461 
    2462 The goal for \CFA I/O is to make I/O as simple as possible for the general case, while fully supporting polmorphism and user defined types in a consistent way.
    2463 The general case is printing out a sequence of variables separated by whitespace.
    2464 \begin{lstlisting}
    2465 int x = 0, y = 1, z = 2;
    2466 sout | x | y | z | endl;
    2467 
    2468 cout << x << " " << y << " " << z << endl;
    2469 \end{lstlisting}
    2470 The \CC form takes almost twice as many characters.
    2471 
    2472 The logical-or operator is used because it is the lowest priority overloadable operator, other than assignment.
    2473 Therefore, most output expressions do not require parenthesis.
    2474 \begin{lstlisting}
    2475 int x = 0, y = 1, z = 2;
    2476 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
    2477 
    2478 cout << x * 3 << y + 1 << (z << 2) << (x == y) << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
    2479 \end{lstlisting}
    2480 
    2481 Finally, the logical-or operator has a link with the Shell pipe-operator for moving data, although data flows in the opposite direction.
    2482 
    2483 \begin{figure}
    2484 \begin{lstlisting}[mathescape=off]
    2485 #include <fstream>
    2486 
    2487 int main() {
    2488         char c;
    2489         short int si;
    2490         unsigned short int usi;
    2491         int i;
    2492         unsigned int ui;
    2493         long int li;
    2494         unsigned long int uli;
    2495         long long int lli;
    2496         unsigned long long int ulli;
    2497         float f;
    2498         double d;
    2499         long double ld;
    2500         float _Complex fc;
    2501         double _Complex dc;
    2502         long double _Complex ldc;
    2503         char s1[10], s2[10];
    2504 
    2505         ifstream in;
    2506         open( &in, "read.data", "r" );
    2507 
    2508         &in | &c
    2509                 | &si | &usi | &i | &ui | &li | &uli | &lli | &ulli
    2510                 | &f | &d | &ld
    2511                 | &fc | &dc | &ldc
    2512                 | str( s1 ) | str( s2, 10 );
    2513 
    2514         sout | c | ' ' | endl
    2515                  | si | usi | i | ui | li | uli | lli | ulli | endl
    2516                  | f | d | ld | endl
    2517                  | f | "" | d | "" | ld | endl;
    2518 
    2519         sepSet( sout, ", $" );
    2520         sout | fc | dc | ldc | endl
    2521                  | sepOn | s1 | sepOff | s2 | endl
    2522                  | s1 | "" | s2 | endl;
    2523 }
    2524 
    2525 $ cat read.data
    2526 A 1 2 3 4 5 6 7 8 1.1 1.2 1.3 1.1+2.3 1.1-2.3 1.1-2.3 abc xyz
    2527 $ a.out
    2528 A
    2529 1 2 3 4 5 6 7 8
    2530 1.1 1.2 1.3
    2531 1.11.21.3
    2532 1.1+2.3i, $1.1-2.3i, $1.1-2.3i
    2533 , $abcxyz
    2534 abcxyz
    2535 \end{lstlisting}
    2536 \end{figure}
    2537 
    2538 
    2539 \section{Standard Library}
    2540 \label{s:StandardLibrary}
    2541 
    2542 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.
    2543 
    2544 
    2545 \subsection{malloc}
    2546 
    2547 \begin{lstlisting}
    2548 forall( otype T ) T * malloc( void );
    2549 forall( otype T ) T * malloc( char fill );
    2550 forall( otype T ) T * malloc( T * ptr, size_t size );
    2551 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
    2552 forall( otype T ) T * calloc( size_t size );
    2553 forall( otype T ) T * realloc( T * ptr, size_t size );
    2554 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
    2555 
    2556 forall( otype T ) T * aligned_alloc( size_t alignment );
    2557 forall( otype T ) T * memalign( size_t alignment );             // deprecated
    2558 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
    2559 
    2560 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
    2561 forall( otype T ) T * memset( T * ptr );                                // remove when default value available
    2562 \end{lstlisting}
    2563 
    2564 
    2565 \subsection{ato/strto}
    2566 
    2567 \begin{lstlisting}
    2568 int ato( const char * ptr );
    2569 unsigned int ato( const char * ptr );
    2570 long int ato( const char * ptr );
    2571 unsigned long int ato( const char * ptr );
    2572 long long int ato( const char * ptr );
    2573 unsigned long long int ato( const char * ptr );
    2574 float ato( const char * ptr );
    2575 double ato( const char * ptr );
    2576 long double ato( const char * ptr );
    2577 float _Complex ato( const char * ptr );
    2578 double _Complex ato( const char * ptr );
    2579 long double _Complex ato( const char * ptr );
    2580 
    2581 int strto( const char * sptr, char ** eptr, int base );
    2582 unsigned int strto( const char * sptr, char ** eptr, int base );
    2583 long int strto( const char * sptr, char ** eptr, int base );
    2584 unsigned long int strto( const char * sptr, char ** eptr, int base );
    2585 long long int strto( const char * sptr, char ** eptr, int base );
    2586 unsigned long long int strto( const char * sptr, char ** eptr, int base );
    2587 float strto( const char * sptr, char ** eptr );
    2588 double strto( const char * sptr, char ** eptr );
    2589 long double strto( const char * sptr, char ** eptr );
    2590 float _Complex strto( const char * sptr, char ** eptr );
    2591 double _Complex strto( const char * sptr, char ** eptr );
    2592 long double _Complex strto( const char * sptr, char ** eptr );
    2593 \end{lstlisting}
    2594 
    2595 
    2596 \subsection{bsearch/qsort}
    2597 
    2598 \begin{lstlisting}
    2599 forall( otype T | { int ?<?( T, T ); } )
    2600 T * bsearch( const T key, const T * arr, size_t dimension );
    2601 
    2602 forall( otype T | { int ?<?( T, T ); } )
    2603 void qsort( const T * arr, size_t dimension );
    2604 \end{lstlisting}
    2605 
    2606 
    2607 \subsection{abs}
    2608 
    2609 \begin{lstlisting}
    2610 char abs( char );
    2611 extern "C" {
    2612 int abs( int );         // use default C routine for int
    2613 } // extern
    2614 long int abs( long int );
    2615 long long int abs( long long int );
    2616 float abs( float );
    2617 double abs( double );
    2618 long double abs( long double );
    2619 float _Complex abs( float _Complex );
    2620 double _Complex abs( double _Complex );
    2621 long double _Complex abs( long double _Complex );
    2622 \end{lstlisting}
    2623 
    2624 
    2625 \subsection{random}
    2626 
    2627 \begin{lstlisting}
    2628 void randseed( long int s );
    2629 char random();
    2630 int random();
    2631 unsigned int random();
    2632 long int random();
    2633 unsigned long int random();
    2634 float random();
    2635 double random();
    2636 float _Complex random();
    2637 double _Complex random();
    2638 long double _Complex random();
    2639 \end{lstlisting}
    2640 
    2641 
    2642 \subsection{min/max/swap}
    2643 
    2644 \begin{lstlisting}
    2645 forall( otype T | { int ?<?( T, T ); } )
    2646 T min( const T t1, const T t2 );
    2647 
    2648 forall( otype T | { int ?>?( T, T ); } )
    2649 T max( const T t1, const T t2 );
    2650 
    2651 forall( otype T )
    2652 void swap( T * t1, T * t2 );
    2653 \end{lstlisting}
     2350\section{Syntactic Anomalies}
     2351
     2352The number 0 and 1 are treated specially in \CFA, and can be redefined as variables.
     2353One syntactic anomaly is when a field in an structure is names 0 or 1:
     2354\begin{lstlisting}
     2355struct S {
     2356        int 0, 1;
     2357} s;
     2358\end{lstlisting}
     2359The problem occurs in accesing these fields using the selection operation ``\lstinline@.@'':
     2360\begin{lstlisting}
     2361s.0 = 0;        // ambiguity with floating constant .0
     2362s.1 = 1;        // ambiguity with floating constant .1
     2363\end{lstlisting}
     2364To make this work, a space is required after the field selection:
     2365\begin{lstlisting}
     2366®s.§\textvisiblespace§0® = 0;
     2367®s.§\textvisiblespace§1® = 1;
     2368\end{lstlisting}
     2369While this sytact is awkward, it is unlikely many programers will name fields of a structure 0 or 1.
     2370Like the \CC lexical problem with closing template-syntax, e.g, \lstinline@Foo<Bar<int®>>®@, this issue can be solved with a more powerful lexer/parser.
     2371
     2372There are several ambiguous cases with operator identifiers, e.g., \lstinline@int *?*?()@, where the string \lstinline@*?*?@ can be lexed as \lstinline@*@/\lstinline@?*?@ or \lstinline@*?@/\lstinline@*?@.
     2373Since it is common practise to put a unary operator juxtaposed to an identifier, e.g., \lstinline@*i@, users will be annoyed if they cannot do this with respect to operator identifiers.
     2374Even with this special hack, there are 5 general cases that cannot be handled.
     2375The first case is for the function-call identifier \lstinline@?()@:
     2376\begin{lstlisting}
     2377int *§\textvisiblespace§?()();  // declaration: space required after '*'
     2378*§\textvisiblespace§?()();              // expression: space required after '*'
     2379\end{lstlisting}
     2380Without the space, the string \lstinline@*?()@ is ambiguous without N character look ahead;
     2381it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument/parameter list.
     2382
     2383The 4 remaining cases occur in expressions:
     2384\begin{lstlisting}
     2385i++§\textvisiblespace§?i:0;             // space required before '?'
     2386i--§\textvisiblespace§?i:0;             // space required before '?'
     2387i§\textvisiblespace§?++i:0;             // space required after '?'
     2388i§\textvisiblespace§?--i:0;             // space required after '?'
     2389\end{lstlisting}
     2390In the first two cases, the string \lstinline@i++?@ is ambiguous, where this string can be lexed as \lstinline@i@ / \lstinline@++?@ or \lstinline@i++@ / \lstinline@?@;
     2391it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list.
     2392In the second two cases, the string \lstinline@?++x@ is ambiguous, where this string can be lexed as \lstinline@?++@ / \lstinline@x@ or \lstinline@?@ / y\lstinline@++x@;
     2393it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list.
    26542394
    26552395
     
    26762416
    26772417task creates a type with implicit locking, separate stack, and a thread
     2418
    26782419
    26792420\subsection{Monitors}
     
    35763317
    35773318
    3578 \subsection{Comparing Key Features of \CFA}
     3319\subsection[Comparing Key Features of CFA]{Comparing Key Features of \CFA}
    35793320
    35803321
     
    37753516\multicolumn{1}{c|}{\textbf{\CFA/\CC}} & \multicolumn{1}{c|}{\textbf{Go}} & \multicolumn{1}{c}{\textbf{Rust}}   \\
    37763517\hline
    3777 \begin{lstlisting}
     3518\begin{lstlisting}[boxpos=t]
    37783519extern "C" {
    37793520#include <sys/types.h>
     
    37823523}
    37833524size_t fileSize( const char *path ) {
    3784         stat s;
     3525        struct stat s;
    37853526        stat(path, &s);
    37863527        return s.st_size;
     
    37883529\end{lstlisting}
    37893530&
    3790 \begin{lstlisting}
     3531\begin{lstlisting}[boxpos=t]
    37913532/*
    37923533#cgo
     
    38073548\end{lstlisting}
    38083549&
    3809 \begin{lstlisting}
     3550\begin{lstlisting}[boxpos=t]
    38103551use libc::{c_int, size_t};
    3811 
    3812 // The following declarations are
    38133552// translated from sys/stat.h
    38143553#[repr(C)]
     
    38183557        ...
    38193558}
    3820 
    38213559#[link(name = "libc")]
    38223560extern {
     
    38243562        buf: *mut stat_t) -> c_int;
    38253563}
    3826 
    38273564fn fileSize(path: *const u8) -> size_t
    38283565{
    38293566        unsafe {
    3830         let mut buf: stat_t = uninit();
    3831         stat(path, &mut buf);
    3832         buf.st_size
     3567                let mut buf: stat_t = uninit();
     3568                stat(path, &mut buf);
     3569                buf.st_size
    38333570        }
    38343571}
     
    39533690
    39543691
    3955 \subsubsection{Modules/Packages}
     3692\begin{comment}
     3693\subsubsection{Modules / Packages}
    39563694
    39573695\begin{lstlisting}
     
    40323770}
    40333771\end{lstlisting}
     3772\end{comment}
     3773
    40343774
    40353775\subsubsection{Parallel Tasks}
     
    41873927\end{flushleft}
    41883928
     3929\lstset{basicstyle=\sf\relsize{-1}}
     3930
     3931
    41893932\subsection{Summary of Language Comparison}
    41903933
    41913934
    4192 \subsubsection{\CC}
     3935\subsubsection[C++]{\CC}
    41933936
    41943937\CC is a general-purpose programming language.
     
    42553998
    42563999
     4000\appendix
     4001
     4002
     4003\section{Incompatible}
     4004
     4005The following incompatibles exist between C and \CFA, and are similar to Annex C for \CC~\cite{ANSI14:C++}.
     4006
     4007\begin{enumerate}
     4008\item
     4009Change type of character literal \lstinline@int@ to \lstinline@char@.
     4010This change allows overloading differentiation argument type matching, e.g.:
     4011\begin{lstlisting}
     4012int function( int i );
     4013int function( char c );
     4014function( 'x' );
     4015\end{lstlisting}
     4016It is preferable that this call match the second version of function rather than the first. \\
     4017Effect on original feature: Change to semantics of well-defined feature. ISO C programs which depend on
     4018\begin{lstlisting}
     4019sizeof('x') == sizeof(int)
     4020\end{lstlisting}
     4021will not work the same as C++ programs. \\
     4022Difficulty of converting: Simple. \\
     4023How widely used: Programs which depend upon sizeof('x') are probably rare.
     4024
     4025\item
     4026Change: String literals made \lstinline@const@ \\
     4027The type of a string literal is changed from \lstinline@array of char@ to \lstinline@array of const char@.
     4028The type of a wide string literal is changed from \lstinline@array of wchar_t@ to \lstinline@array of const wchar_t@. \\
     4029Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument.
     4030Effect on original feature: Change to semantics of well-defined feature. \\
     4031Difficulty of converting: Simple syntactic transformation, because string literals can be converted to \lstinline@char*;@ (4.2).
     4032The most common cases are handled by a new but deprecated standard conversion:
     4033\begin{lstlisting}
     4034char* p = "abc"; // valid in C, deprecated in C++
     4035char* q = expr ? "abc" : "de"; // valid in C, invalid in C++
     4036\end{lstlisting}
     4037How widely used: Programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are probably rare.
     4038
     4039\item
     4040Change: C++ does not have \emph{tentative definitions} as in C.
     4041E.g., at file scope,
     4042\begin{lstlisting}
     4043int i;
     4044int i;
     4045\end{lstlisting}
     4046is valid in C, invalid in C++.
     4047This makes it impossible to define mutually referential file-local static
     4048objects, if initializers are restricted to the syntactic forms of C. For example,
     4049\begin{lstlisting}
     4050struct X { int i; struct X *next; };
     4051static struct X a;
     4052static struct X b = { 0, &a };
     4053static struct X a = { 1, &b };
     4054\end{lstlisting}
     4055Rationale: This avoids having different initialization rules for builtin types and userdefined types.
     4056Effect on original feature: Deletion of semantically welldefined feature. \\
     4057Difficulty of converting: Semantic transformation.
     4058In C++, the initializer for one of a set of mutuallyreferential filelocal static objects must invoke a function call to achieve the initialization.
     4059How widely used: Seldom.
     4060
     4061\item
     4062Change: A struct is a scope in C++, not in C \\
     4063Rationale: Class scope is crucial to C++, and a struct is a class. \\
     4064Effect on original feature: Change to semantics of well-defined feature. \\
     4065Difficulty of converting: Semantic transformation. \\
     4066How widely used: C programs use struct extremely frequently, but the change is only noticeable when struct, enumeration, or enumerator names are referred to outside the struct.
     4067The latter is probably rare.
     4068
     4069\CFA is C \emph{incompatible} on this issue, and provides semantics similar to \CC.
     4070Nested types are not hoisted and can be referenced using the field selection operator ``\lstinline@.@'', unlike the \CC scope-resolution operator ``\lstinline@::@''.
     4071Given that nested types in C are equivalent to not using them, i.e., they are essentially useless, it is unlikely there are any realistic usages that break because of this incompatibility.
     4072
     4073\item
     4074Change: In C++, the name of a nested class is local to its enclosing class.
     4075In C the name of the nested class belongs to the same scope as the name of the outermost enclosing class
     4076Example:
     4077\begin{lstlisting}
     4078struct X {
     4079struct Y { /* ... */ } y;
     4080};
     4081struct Y yy; // valid C, invalid C++
     4082\end{lstlisting}
     4083Rationale: C++ classes have member functions which require that classes establish scopes.
     4084The C rule would leave classes as an incomplete scope mechanism which would prevent C++ programmers from maintaining locality within a class. A coherent set of scope rules for C++ based on the C rule would be very complicated and C++ programmers would be unable to predict reliably the meanings of nontrivial examples involving nested or local functions.
     4085Effect on original feature: Change of semantics of welldefined feature.
     4086Difficulty 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:
     4087\begin{lstlisting}
     4088struct Y; // struct Y and struct X are at the same scope
     4089struct X {
     4090struct Y { /* ... */ } y;
     4091};
     4092\end{lstlisting}
     4093All 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.
     4094Note: this is a consequence of the difference in scope rules, which is documented in 3.3.
     4095How widely used: Seldom.
     4096\end{enumerate}
     4097
     4098
     4099\section{I/O Library}
     4100\label{s:IOLibrary}
     4101\index{input/output library}
     4102
     4103The goal for \CFA I/O is to make I/O as simple as possible for the general case, while fully supporting polmorphism and user defined types in a consistent way.
     4104The general case is printing out a sequence of variables separated by whitespace.
     4105\begin{quote2}
     4106\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     4107\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{\CC}}      \\
     4108\begin{lstlisting}
     4109int x = 0, y = 1, z = 2;
     4110®sout® ®|® x ®|® y ®|® z ®| endl®;
     4111\end{lstlisting}
     4112&
     4113\begin{lstlisting}
     4114
     4115cout << x << " " << y << " " << z << endl;
     4116\end{lstlisting}
     4117\end{tabular}
     4118\end{quote2}
     4119The \CFA form is half as many characters, and is similar to \Index{Python} I/O with respect to implicit separators.
     4120
     4121The logical-or operator is used because it is the lowest-priority overloadable operator, other than assignment.
     4122Therefore, fewer output expressions require parenthesis.
     4123\begin{quote2}
     4124\begin{tabular}{@{}ll@{}}
     4125\textbf{\CFA:}
     4126&
     4127\begin{lstlisting}
     4128sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     4129\end{lstlisting}
     4130\\
     4131\textbf{\CC:}
     4132&
     4133\begin{lstlisting}
     4134cout << x * 3 << y + 1 << (z << 2) << (x == y) << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
     4135\end{lstlisting}
     4136\end{tabular}
     4137\end{quote2}
     4138Finally, the logical-or operator has a link with the Shell pipe-operator for moving data, although data flows in the opposite direction.
     4139
     4140The implicit seperator\index{I/O separator} character (space/blank) is a separator not a terminator.
     4141The rules for implicitly adding the separator are:
     4142\begin{enumerate}
     4143\item
     4144A seperator does not appear at the start or end of a line.
     4145\begin{lstlisting}[belowskip=0pt]
     4146sout | 1 | 2 | 3 | endl;
     4147\end{lstlisting}
     4148\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     41491 2 3
     4150\end{lstlisting}
     4151\item
     4152A seperator does not appear before or after a character literal or variable.
     4153\begin{lstlisting}
     4154sout | '1' | '2' | '3' | endl;
     4155123
     4156\end{lstlisting}
     4157\item
     4158A seperator does not appear before or after a null (empty) C string
     4159\begin{lstlisting}
     4160sout | 1 | "" | 2 | "" | 3 | endl;
     4161123
     4162\end{lstlisting}
     4163which is a local mechanism to disable insertion of the separator character.
     4164\item
     4165A seperator does not appear before a C string starting with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off]@([{$£¥¡¿«@
     4166%$
     4167\begin{lstlisting}[mathescape=off]
     4168sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x $" | 4 | "x £" | 5 | "x ¥" | 6 | "x ¡" | 7 | "x ¿" | 8 | "x «" | 9 | endl;
     4169\end{lstlisting}
     4170%$
     4171\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     4172x (1 x [2 x {3 x $4 x £5 x ¥6 x ¡7 x ¿8 x «9
     4173\end{lstlisting}
     4174%$
     4175\item
     4176A seperator does not appear after a C string ending with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline@,.:;!?)]}%¢»@
     4177\begin{lstlisting}[belowskip=0pt]
     4178sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7 | ") x" | 8 | "] x" | 9 | "} x"
     4179         | 10 | "% x" | 11 | "¢ x" | 12 | "» x" | endl;
     4180\end{lstlisting}
     4181\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     41821, x 2. x 3: x 4; x 5! x 6? x 7) x 8] x 9} x 10% x 11¢ 12»
     4183\end{lstlisting}
     4184\item
     4185A 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@
     4186\begin{lstlisting}[belowskip=0pt]
     4187sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x" | "x " | 4 | " x" | "x\t" | 1 | "\tx" | endl;
     4188\end{lstlisting}
     4189\begin{lstlisting}[mathescape=off,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     4190x`1`x'2'x"3"x x 4 x x   1       x
     4191\end{lstlisting}
     4192\end{enumerate}
     4193The following \CC-style \Index{manipulator}s allow further control over implicit seperation.
     4194\begin{lstlisting}[mathescape=off,belowskip=0pt]
     4195sout | sepOn | 1 | 2 | 3 | sepOn | endl;        // separator at start of line
     4196\end{lstlisting}
     4197\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     4198 1 2 3
     4199\end{lstlisting}
     4200\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     4201sout | 1 | sepOff | 2 | 3 | endl;                       // turn off implicit separator temporarily
     4202\end{lstlisting}
     4203\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     420412 3
     4205\end{lstlisting}
     4206\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     4207sout | sepDisable | 1 | 2 | 3 | endl;           // turn off implicit separation, affects all subsequent prints
     4208\end{lstlisting}
     4209\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     4210123
     4211\end{lstlisting}
     4212\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     4213sout | 1 | sepOn | 2 | 3 | endl;                        // turn on implicit separator temporarily
     4214\end{lstlisting}
     4215\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     42161 23
     4217\end{lstlisting}
     4218\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     4219sout | sepEnable | 1 | 2 | 3 | endl;            // turn on implicit separation, affects all subsequent prints
     4220\end{lstlisting}
     4221\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     4222 1 2 3
     4223\end{lstlisting}
     4224\begin{lstlisting}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt]
     4225sepSet( sout, ", $" );                                          // change separator from " " to ", $"
     4226sout | 1 | 2 | 3 | endl;
     4227\end{lstlisting}
     4228%$
     4229\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt]
     42301, $2, $3
     4231\end{lstlisting}
     4232%$
     4233\begin{comment}
     4234#include <fstream>
     4235
     4236int main() {
     4237        int x = 3, y = 5, z = 7;
     4238        sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     4239        sout | 1 | 2 | 3 | endl;
     4240        sout | '1' | '2' | '3' | endl;
     4241        sout | 1 | "" | 2 | "" | 3 | endl;
     4242        sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x $" | 4 | "x £" | 5 | "x ¥" | 6 | "x ¡" | 7 | "x ¿" | 8 | "x «" | 9 | endl;
     4243        sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7 | ") x" | 8 | "] x" | 9 | "} x"
     4244                 | 10 | "% x" | 11 | "¢ x" | 12 | "» x" | endl;
     4245        sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x" | "x " | 4 | " x" | "x\t" | 1 | "\tx" | endl;
     4246        sout | sepOn | 1 | 2 | 3 | sepOn | endl;        // separator at start of line
     4247        sout | 1 | sepOff | 2 | 3 | endl;                       // turn off implicit separator temporarily
     4248        sout | sepDisable | 1 | 2 | 3 | endl;           // turn off implicit separation, affects all subsequent prints
     4249        sout | 1 | sepOn | 2 | 3 | endl;                        // turn on implicit separator temporarily
     4250        sout | sepEnable | 1 | 2 | 3 | endl;            // turn on implicit separation, affects all subsequent prints
     4251        sepSet( sout, ", $" );                                          // change separator from " " to ", $"
     4252        sout | 1 | 2 | 3 | endl;
     4253
     4254}
     4255
     4256// Local Variables: //
     4257// tab-width: 4 //
     4258// End: //
     4259\end{comment}
     4260%$
     4261
     4262
     4263\section{Standard Library}
     4264\label{s:StandardLibrary}
     4265
     4266The goal of the \CFA standard-library is to wrap many of the existing C library-routines that are explicitly polymorphic into implicitly polymorphic versions.
     4267
     4268
     4269\subsection{malloc}
     4270
     4271\begin{lstlisting}
     4272forall( otype T ) T * malloc( void );§\indexc{malloc}§
     4273forall( otype T ) T * malloc( char fill );
     4274forall( otype T ) T * malloc( T * ptr, size_t size );
     4275forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
     4276forall( otype T ) T * calloc( size_t nmemb );§\indexc{calloc}§
     4277forall( otype T ) T * realloc( T * ptr, size_t size );§\indexc{ato}§
     4278forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
     4279
     4280forall( otype T ) T * aligned_alloc( size_t alignment );§\indexc{ato}§
     4281forall( otype T ) T * memalign( size_t alignment );             // deprecated
     4282forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
     4283
     4284forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
     4285forall( otype T ) T * memset( T * ptr );                                // remove when default value available
     4286\end{lstlisting}
     4287
     4288
     4289\subsection{ato / strto}
     4290
     4291\begin{lstlisting}
     4292int ato( const char * ptr );§\indexc{ato}§
     4293unsigned int ato( const char * ptr );
     4294long int ato( const char * ptr );
     4295unsigned long int ato( const char * ptr );
     4296long long int ato( const char * ptr );
     4297unsigned long long int ato( const char * ptr );
     4298float ato( const char * ptr );
     4299double ato( const char * ptr );
     4300long double ato( const char * ptr );
     4301float _Complex ato( const char * ptr );
     4302double _Complex ato( const char * ptr );
     4303long double _Complex ato( const char * ptr );
     4304
     4305int strto( const char * sptr, char ** eptr, int base );
     4306unsigned int strto( const char * sptr, char ** eptr, int base );
     4307long int strto( const char * sptr, char ** eptr, int base );
     4308unsigned long int strto( const char * sptr, char ** eptr, int base );
     4309long long int strto( const char * sptr, char ** eptr, int base );
     4310unsigned long long int strto( const char * sptr, char ** eptr, int base );
     4311float strto( const char * sptr, char ** eptr );
     4312double strto( const char * sptr, char ** eptr );
     4313long double strto( const char * sptr, char ** eptr );
     4314float _Complex strto( const char * sptr, char ** eptr );
     4315double _Complex strto( const char * sptr, char ** eptr );
     4316long double _Complex strto( const char * sptr, char ** eptr );
     4317\end{lstlisting}
     4318
     4319
     4320\subsection{bsearch / qsort}
     4321
     4322\begin{lstlisting}
     4323forall( otype T | { int ?<?( T, T ); } )
     4324T * bsearch( const T key, const T * arr, size_t dimension );§\indexc{bsearch}§
     4325
     4326forall( otype T | { int ?<?( T, T ); } )
     4327void qsort( const T * arr, size_t dimension );§\indexc{qsort}§
     4328\end{lstlisting}
     4329
     4330
     4331\subsection{abs}
     4332
     4333\begin{lstlisting}
     4334char abs( char );§\indexc{abs}§
     4335int abs( int );
     4336long int abs( long int );
     4337long long int abs( long long int );
     4338float abs( float );
     4339double abs( double );
     4340long double abs( long double );
     4341float abs( float _Complex );
     4342double abs( double _Complex );
     4343long double abs( long double _Complex );
     4344\end{lstlisting}
     4345
     4346
     4347\subsection{random}
     4348
     4349\begin{lstlisting}
     4350void rand48seed( long int s );§\indexc{rand48seed}§
     4351char rand48();§\indexc{rand48}§
     4352int rand48();
     4353unsigned int rand48();
     4354long int rand48();
     4355unsigned long int rand48();
     4356float rand48();
     4357double rand48();
     4358float _Complex rand48();
     4359double _Complex rand48();
     4360long double _Complex rand48();
     4361\end{lstlisting}
     4362
     4363
     4364\subsection{min / max / swap}
     4365
     4366\begin{lstlisting}
     4367forall( otype T | { int ?<?( T, T ); } )
     4368T min( const T t1, const T t2 );§\indexc{min}§
     4369
     4370forall( otype T | { int ?>?( T, T ); } )
     4371T max( const T t1, const T t2 );§\indexc{max}§
     4372
     4373forall( otype T )
     4374void swap( T * t1, T * t2 );§\indexc{swap}§
     4375\end{lstlisting}
     4376
     4377
     4378\section{Math Library}
     4379\label{s:Math Library}
     4380
     4381The 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.
     4382
     4383
     4384\subsection{General}
     4385
     4386\begin{lstlisting}
     4387float fabs( float );§\indexc{fabs}§
     4388double fabs( double );
     4389long double fabs( long double );
     4390float cabs( float _Complex );
     4391double cabs( double _Complex );
     4392long double cabs( long double _Complex );
     4393
     4394float ?%?( float, float );§\indexc{fmod}§
     4395float fmod( float, float );
     4396double ?%?( double, double );
     4397double fmod( double, double );
     4398long double ?%?( long double, long double );
     4399long double fmod( long double, long double );
     4400
     4401float remainder( float, float );§\indexc{remainder}§
     4402double remainder( double, double );
     4403long double remainder( long double, long double );
     4404
     4405[ int, float ] remquo( float, float );§\indexc{remquo}§
     4406float remquo( float, float, int * );
     4407[ int, double ] remquo( double, double );
     4408double remquo( double, double, int * );
     4409[ int, long double ] remquo( long double, long double );
     4410long double remquo( long double, long double, int * );
     4411
     4412[ int, float ] div( float, float );                                             // alternative name for remquo
     4413float div( float, float, int * );§\indexc{div}§
     4414[ int, double ] div( double, double );
     4415double div( double, double, int * );
     4416[ int, long double ] div( long double, long double );
     4417long double div( long double, long double, int * );
     4418
     4419float fma( float, float, float );§\indexc{fma}§
     4420double fma( double, double, double );
     4421long double fma( long double, long double, long double );
     4422
     4423float fdim( float, float );§\indexc{fdim}§
     4424double fdim( double, double );
     4425long double fdim( long double, long double );
     4426
     4427float nan( const char * );§\indexc{nan}§
     4428double nan( const char * );
     4429long double nan( const char * );
     4430\end{lstlisting}
     4431
     4432
     4433\subsection{Exponential}
     4434
     4435\begin{lstlisting}
     4436float exp( float );§\indexc{exp}§
     4437double exp( double );
     4438long double exp( long double );
     4439float _Complex exp( float _Complex );
     4440double _Complex exp( double _Complex );
     4441long double _Complex exp( long double _Complex );
     4442
     4443float exp2( float );§\indexc{exp2}§
     4444double exp2( double );
     4445long double exp2( long double );
     4446float _Complex exp2( float _Complex );
     4447double _Complex exp2( double _Complex );
     4448long double _Complex exp2( long double _Complex );
     4449
     4450float expm1( float );§\indexc{expm1}§
     4451double expm1( double );
     4452long double expm1( long double );
     4453
     4454float log( float );§\indexc{log}§
     4455double log( double );
     4456long double log( long double );
     4457float _Complex log( float _Complex );
     4458double _Complex log( double _Complex );
     4459long double _Complex log( long double _Complex );
     4460
     4461float log2( float );§\indexc{log2}§
     4462double log2( double );
     4463long double log2( long double );
     4464float _Complex log2( float _Complex );
     4465double _Complex log2( double _Complex );
     4466long double _Complex log2( long double _Complex );
     4467
     4468float log10( float );§\indexc{log10}§
     4469double log10( double );
     4470long double log10( long double );
     4471float _Complex log10( float _Complex );
     4472double _Complex log10( double _Complex );
     4473long double _Complex log10( long double _Complex );
     4474
     4475float log1p( float );§\indexc{log1p}§
     4476double log1p( double );
     4477long double log1p( long double );
     4478
     4479int ilogb( float );§\indexc{ilogb}§
     4480int ilogb( double );
     4481int ilogb( long double );
     4482
     4483float logb( float );§\indexc{logb}§
     4484double logb( double );
     4485long double logb( long double );
     4486\end{lstlisting}
     4487
     4488
     4489\subsection{Power}
     4490
     4491\begin{lstlisting}
     4492float sqrt( float );§\indexc{sqrt}§
     4493double sqrt( double );
     4494long double sqrt( long double );
     4495float _Complex sqrt( float _Complex );
     4496double _Complex sqrt( double _Complex );
     4497long double _Complex sqrt( long double _Complex );
     4498
     4499float cbrt( float );§\indexc{cbrt}§
     4500double cbrt( double );
     4501long double cbrt( long double );
     4502
     4503float hypot( float, float );§\indexc{hypot}§
     4504double hypot( double, double );
     4505long double hypot( long double, long double );
     4506
     4507float pow( float, float );§\indexc{pow}§
     4508double pow( double, double );
     4509long double pow( long double, long double );
     4510float _Complex pow( float _Complex, float _Complex );
     4511double _Complex pow( double _Complex, double _Complex );
     4512long double _Complex pow( long double _Complex, long double _Complex );
     4513\end{lstlisting}
     4514
     4515
     4516\subsection{Trigonometric}
     4517
     4518\begin{lstlisting}
     4519float sin( float );§\indexc{sin}§
     4520double sin( double );
     4521long double sin( long double );
     4522float _Complex sin( float _Complex );
     4523double _Complex sin( double _Complex );
     4524long double _Complex sin( long double _Complex );
     4525
     4526float cos( float );§\indexc{cos}§
     4527double cos( double );
     4528long double cos( long double );
     4529float _Complex cos( float _Complex );
     4530double _Complex cos( double _Complex );
     4531long double _Complex cos( long double _Complex );
     4532
     4533float tan( float );§\indexc{tan}§
     4534double tan( double );
     4535long double tan( long double );
     4536float _Complex tan( float _Complex );
     4537double _Complex tan( double _Complex );
     4538long double _Complex tan( long double _Complex );
     4539
     4540float asin( float );§\indexc{asin}§
     4541double asin( double );
     4542long double asin( long double );
     4543float _Complex asin( float _Complex );
     4544double _Complex asin( double _Complex );
     4545long double _Complex asin( long double _Complex );
     4546
     4547float acos( float );§\indexc{acos}§
     4548double acos( double );
     4549long double acos( long double );
     4550float _Complex acos( float _Complex );
     4551double _Complex acos( double _Complex );
     4552long double _Complex acos( long double _Complex );
     4553
     4554float atan( float );§\indexc{atan}§
     4555double atan( double );
     4556long double atan( long double );
     4557float _Complex atan( float _Complex );
     4558double _Complex atan( double _Complex );
     4559long double _Complex atan( long double _Complex );
     4560
     4561float atan2( float, float );§\indexc{atan2}§
     4562double atan2( double, double );
     4563long double atan2( long double, long double );
     4564
     4565float atan( float, float );                                                             // alternative name for atan2
     4566double atan( double, double );§\indexc{atan}§
     4567long double atan( long double, long double );
     4568\end{lstlisting}
     4569
     4570
     4571\subsection{Hyperbolic}
     4572
     4573\begin{lstlisting}
     4574float sinh( float );§\indexc{sinh}§
     4575double sinh( double );
     4576long double sinh( long double );
     4577float _Complex sinh( float _Complex );
     4578double _Complex sinh( double _Complex );
     4579long double _Complex sinh( long double _Complex );
     4580
     4581float cosh( float );§\indexc{cosh}§
     4582double cosh( double );
     4583long double cosh( long double );
     4584float _Complex cosh( float _Complex );
     4585double _Complex cosh( double _Complex );
     4586long double _Complex cosh( long double _Complex );
     4587
     4588float tanh( float );§\indexc{tanh}§
     4589double tanh( double );
     4590long double tanh( long double );
     4591float _Complex tanh( float _Complex );
     4592double _Complex tanh( double _Complex );
     4593long double _Complex tanh( long double _Complex );
     4594
     4595float asinh( float );§\indexc{asinh}§
     4596double asinh( double );
     4597long double asinh( long double );
     4598float _Complex asinh( float _Complex );
     4599double _Complex asinh( double _Complex );
     4600long double _Complex asinh( long double _Complex );
     4601
     4602float acosh( float );§\indexc{acosh}§
     4603double acosh( double );
     4604long double acosh( long double );
     4605float _Complex acosh( float _Complex );
     4606double _Complex acosh( double _Complex );
     4607long double _Complex acosh( long double _Complex );
     4608
     4609float atanh( float );§\indexc{atanh}§
     4610double atanh( double );
     4611long double atanh( long double );
     4612float _Complex atanh( float _Complex );
     4613double _Complex atanh( double _Complex );
     4614long double _Complex atanh( long double _Complex );
     4615\end{lstlisting}
     4616
     4617
     4618\subsection{Error / Gamma}
     4619
     4620\begin{lstlisting}
     4621float erf( float );§\indexc{erf}§
     4622double erf( double );
     4623long double erf( long double );
     4624float _Complex erf( float _Complex );
     4625double _Complex erf( double _Complex );
     4626long double _Complex erf( long double _Complex );
     4627
     4628float erfc( float );§\indexc{erfc}§
     4629double erfc( double );
     4630long double erfc( long double );
     4631float _Complex erfc( float _Complex );
     4632double _Complex erfc( double _Complex );
     4633long double _Complex erfc( long double _Complex );
     4634
     4635float lgamma( float );§\indexc{lgamma}§
     4636double lgamma( double );
     4637long double lgamma( long double );
     4638float lgamma( float, int * );
     4639double lgamma( double, int * );
     4640long double lgamma( long double, int * );
     4641
     4642float tgamma( float );§\indexc{tgamma}§
     4643double tgamma( double );
     4644long double tgamma( long double );
     4645\end{lstlisting}
     4646
     4647
     4648\subsection{Nearest Integer}
     4649
     4650\begin{lstlisting}
     4651float floor( float );§\indexc{floor}§
     4652double floor( double );
     4653long double floor( long double );
     4654
     4655float ceil( float );§\indexc{ceil}§
     4656double ceil( double );
     4657long double ceil( long double );
     4658
     4659float trunc( float );§\indexc{trunc}§
     4660double trunc( double );
     4661long double trunc( long double );
     4662
     4663float rint( float );§\indexc{rint}§
     4664long double rint( long double );
     4665long int rint( float );
     4666long int rint( double );
     4667long int rint( long double );
     4668long long int rint( float );
     4669long long int rint( double );
     4670long long int rint( long double );
     4671
     4672long int lrint( float );§\indexc{lrint}§
     4673long int lrint( double );
     4674long int lrint( long double );
     4675long long int llrint( float );
     4676long long int llrint( double );
     4677long long int llrint( long double );
     4678
     4679float nearbyint( float );§\indexc{nearbyint}§
     4680double nearbyint( double );
     4681long double nearbyint( long double );
     4682
     4683float round( float );§\indexc{round}§
     4684long double round( long double );
     4685long int round( float );
     4686long int round( double );
     4687long int round( long double );
     4688long long int round( float );
     4689long long int round( double );
     4690long long int round( long double );
     4691
     4692long int lround( float );§\indexc{lround}§
     4693long int lround( double );
     4694long int lround( long double );
     4695long long int llround( float );
     4696long long int llround( double );
     4697long long int llround( long double );
     4698\end{lstlisting}
     4699
     4700
     4701\subsection{Manipulation}
     4702
     4703\begin{lstlisting}
     4704float copysign( float, float );§\indexc{copysign}§
     4705double copysign( double, double );
     4706long double copysign( long double, long double );
     4707
     4708float frexp( float, int * );§\indexc{frexp}§
     4709double frexp( double, int * );
     4710long double frexp( long double, int * );
     4711
     4712float ldexp( float, int );§\indexc{ldexp}§
     4713double ldexp( double, int );
     4714long double ldexp( long double, int );
     4715
     4716[ float, float ] modf( float );§\indexc{modf}§
     4717float modf( float, float * );
     4718[ double, double ] modf( double );
     4719double modf( double, double * );
     4720[ long double, long double ] modf( long double );
     4721long double modf( long double, long double * );
     4722
     4723float nextafter( float, float );§\indexc{nextafter}§
     4724double nextafter( double, double );
     4725long double nextafter( long double, long double );
     4726
     4727float nexttoward( float, long double );§\indexc{nexttoward}§
     4728double nexttoward( double, long double );
     4729long double nexttoward( long double, long double );
     4730
     4731float scalbn( float, int );§\indexc{scalbn}§
     4732double scalbn( double, int );
     4733long double scalbn( long double, int );
     4734
     4735float scalbln( float, long int );§\indexc{scalbln}§
     4736double scalbln( double, long int );
     4737long double scalbln( long double, long int );
     4738\end{lstlisting}
     4739
     4740
     4741\section{Rational Numbers}
     4742\label{s:RationalNumbers}
     4743
     4744Rational numbers are numbers written as a ratio, i.e., as a fraction, where the numerator (top number) and the denominator (bottom number) are whole numbers.
     4745When creating and computing with rational numbers, results are constantly reduced to keep the numerator and denominator as small as possible.
     4746
     4747\begin{lstlisting}
     4748// implementation
     4749struct Rational {§\indexc{Rational}§
     4750        long int numerator, denominator;                                        // invariant: denominator > 0
     4751}; // Rational
     4752
     4753// constants
     4754extern struct Rational 0;
     4755extern struct Rational 1;
     4756
     4757// constructors
     4758Rational rational();
     4759Rational rational( long int n );
     4760Rational rational( long int n, long int d );
     4761
     4762// getter/setter for numerator/denominator
     4763long int numerator( Rational r );
     4764long int numerator( Rational r, long int n );
     4765long int denominator( Rational r );
     4766long int denominator( Rational r, long int d );
     4767
     4768// comparison
     4769int ?==?( Rational l, Rational r );
     4770int ?!=?( Rational l, Rational r );
     4771int ?<?( Rational l, Rational r );
     4772int ?<=?( Rational l, Rational r );
     4773int ?>?( Rational l, Rational r );
     4774int ?>=?( Rational l, Rational r );
     4775
     4776// arithmetic
     4777Rational -?( Rational r );
     4778Rational ?+?( Rational l, Rational r );
     4779Rational ?-?( Rational l, Rational r );
     4780Rational ?*?( Rational l, Rational r );
     4781Rational ?/?( Rational l, Rational r );
     4782
     4783// conversion
     4784double widen( Rational r );
     4785Rational narrow( double f, long int md );
     4786
     4787// I/O
     4788forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
     4789forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
     4790\end{lstlisting}
     4791
     4792
    42574793\bibliographystyle{plain}
    4258 \bibliography{/usr/local/bibliographies/pl.bib}
     4794\bibliography{cfa}
    42594795
    42604796
Note: See TracChangeset for help on using the changeset viewer.