Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    re945826 r6c91065  
    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 
    171% 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)
    242
    253\documentclass[openright,twoside]{article}
     
    275
    286% Latex packages used in the document.
    29 \usepackage[T1]{fontenc}                                % allow Latin1 (extended ASCII) characters
    30 \usepackage{textcomp}
    31 \usepackage[latin1]{inputenc}
    32 \usepackage{upquote}
     7
    338\usepackage{fullpage,times}
    34 \usepackage{epic,eepic}
    359\usepackage{xspace}
    3610\usepackage{varioref}
     
    3812\usepackage{footmisc}
    3913\usepackage{comment}
    40 \usepackage{latexsym}                                   % \Box
    41 \usepackage{mathptmx}                                   % better math font with "times"
     14\usepackage{latexsym}                                   % \Box
     15\usepackage{mathptmx}                                   % better math font with "times"
    4216\usepackage[pagewise]{lineno}
    4317\renewcommand{\linenumberfont}{\scriptsize\sffamily}
     
    4822%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    4923
     24% Names used in the document.
     25
     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)
     30\newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace}
     31
     32%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     33
    5034% Bespoke macros used in the document.
    51 \input{common}
    52 
    53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    54 
    55 % Names used in the document.
    56 
    57 \newcommand{\Version}{1.0.0}
    58 \newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace}
    59 
    60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    61 
    62 \setcounter{secnumdepth}{3}                             % number subsubsections
    63 \setcounter{tocdepth}{3}                                % subsubsections in table of contents
     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{
     168language=CFA,
     169columns=flexible,
     170basicstyle=\sf\relsize{-1},
     171tabsize=4,
     172xleftmargin=\parindent,
     173escapechar=@,
     174mathescape=true,
     175keepspaces=true,
     176showstringspaces=false,
     177showlines=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
    64195\makeindex
    65196
     
    68199\begin{document}
    69200\pagestyle{headings}
    70 \linenumbers                                            % comment out to turn off line numbering
     201\linenumbers                                    % comment out to turn off line numbering
    71202
    72203\title{\Huge
     
    82213}% author
    83214\date{
    84 DRAFT \\
    85 \today
     215DRAFT\\\today
    86216}% date
    87217
     
    111241
    112242\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.
    113 The syntax of the \CFA language builds from C, and should look immediately familiar to C programmers.
     243The syntax of the \CFA language builds from that of C, and should look immediately familiar to C programmers.
    114244% Any language feature that is not described here can be assumed to be using the standard C11 syntax.
    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.
     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.
    116246Like C, \CFA is a statically typed, procedural language with a low-overhead runtime, meaning there is no global garbage-collection.
    117247The primary new features include parametric-polymorphism routines and types, exceptions, concurrency, and modules.
     
    124254New programs can be written in \CFA using a combination of C and \CFA features.
    125255\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.
    126 \CFA has 30 years of hindsight and clean starting point.
     256\CFA has 30 years of hindsight and a much cleaner starting point than \CC.
    127257
    128258Like \CC, there may be both an old and new ways to achieve the same effect.
     
    149279\end{quote2}
    150280Both programs output the same result.
    151 While 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}).
     281While 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}).
    152282
    153283This document is a reference manual for the \CFA programming language, targeted at \CFA programmers.
    154 Implementers may refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
     284Implementers may also refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
    155285In its current state, this document covers the intended core features of the language.
    156286Changes to the syntax and additional features are expected to be included in later revisions.
     
    164294The 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.
    165295A 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.
    166 As 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?}
     296As 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?}
    170300
    171301Even 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.
     
    184314Java~\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.
    185315These languages have different syntax and semantics from C, and do not interoperate directly with C, largely because of garbage collection.
    186 As a result, there is a significant learning curve to move to these languages, and C legacy-code must be rewritten.
     316As a result, there is a significant learning curve to move to these languages, and C legacy-code must be complete rewritten.
    187317These 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.
    188318
     
    201331This feature allows users of \CFA to take advantage of the existing panoply of C libraries from inside their \CFA code.
    202332In 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.
    203 Programming-language developers often state that adequate library support takes more work than designing and implementing the language itself.
     333Programming-language developers often state that adequate library support costs many times more than designing and implementing the language itself.
    204334Like \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.
    205335
     
    208338Whereas, \CFA wraps each of these routines into one with the common name \lstinline@abs@.
    209339\begin{lstlisting}
     340extern "C" {
     341#include <stdlib.h>                     // provide C prototype for integer "abs" routine
     342} // extern "C"
     343
    210344char abs( char );
    211 extern "C" {
    212 int abs( int );                         // use default C routine for int
    213 } // extern "C"
    214 long int abs( long int );
     345long int abs( long int );       // @{\CFA}@ overload name "abs" for other types
    215346long long int abs( long long int );
    216347float abs( float );
     
    229360The name ``\lstinline@abs@'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value.
    230361Hence, knowing the name \lstinline@abs@ should be sufficient to apply it to any type where it is applicable.
    231 The 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}
     362The time savings and safety of using one name uniformly versus @N@ unique names should not be underestimated.
     363
     364
     365\section{Compiling \CFA}
    235366
    236367The command \lstinline@cfa@ is used to compile \CFA program(s).
    237 This command works like the GNU \lstinline@gcc@\index{gcc} command, e.g.:
    238 \begin{lstlisting}
    239 cfa [ gcc-options ] C/§\CFA§-files [ assembler/loader-files ]
    240 \end{lstlisting}
    241 \indexc{cfa}\index{compilation!cfa@\lstinline$cfa$}
    242 By default, \CFA programs having the following \lstinline@gcc@ flags turned on:
     368This command works like the GNU \lstinline@gcc@ command, e.g.:
     369\begin{lstlisting}
     370cfa [ gcc-options ] C/@{\CFA}@-files [ assembler/loader-files ]
     371\end{lstlisting}
     372The following additional option is available:
    243373\begin{description}
    244 \item\hspace*{-4pt}\Indexc{-std=gnu99}\index{compilation option!-std=gnu99@{\lstinline$-std=gnu99$}}
    245 The 1999 C standard plus GNU extensions.
    246 \item\hspace*{-4pt}\Indexc{-fgnu89-¶inline¶}\index{compilation option!-fgnu89-inline@{\lstinline$-fgnu89-¶inline¶$}}
    247 Use the traditional GNU semantics for inline routines in C99 mode.
    248 \end{description}
    249 The following new \CFA option is available:
    250 \begin{description}
    251 \item\hspace*{-4pt}\Indexc{-CFA}\index{compilation option!-CFA@{\lstinline$-CFA$}}
     374\item
     375\hspace*{-4pt}\lstinline@-CFA@
    252376Only 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.
    253377\end{description}
    254378
    255 The following preprocessor variables are available:
    256 \begin{description}
    257 \item\hspace*{-4pt}\Indexc{__CFA__}\index{preprocessor variables!__CFA__@{\lstinline$__CFA__$}}
    258 is always available during preprocessing and its value is the current major \Index{version number} of \CFA.\footnote{
    259 The C preprocessor allows only integer values in a preprocessor variable so a value like ``\Version'' is not allowed.
    260 Hence, 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__$}}
    263 is 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__$}
    266 is 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__$}
    269 is always available during preprocessing and it has no value.
    270 \end{description}
    271 
    272 These preprocessor variables allow conditional compilation of programs that must work differently in these situations.
    273 For 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}
    281 which conditionally includes the correct header file, if the program is compiled using \lstinline@gcc@ or \lstinline@cfa@.
    282 
    283379
    284380\section{Underscores in Constants}
     
    286382Numeric constants are extended to allow \Index{underscore}s within constants\index{constant!underscore}, e.g.:
    287383\begin{lstlisting}
    288 2®_®147®_®483®_®648;                            // decimal constant
     3842_147_483_648;                          // decimal constant
    28938556_ul;                                          // decimal unsigned long constant
    2903860_377;                                          // octal constant
     
    312408the type suffixes \lstinline@U@, \lstinline@L@, etc. may start with an underscore \lstinline@1_U@, \lstinline@1_ll@ or \lstinline@1.0E10_f@.
    313409\end{enumerate}
    314 It is significantly easier to read and enter long constants when they are broken up into smaller groupings (most cultures use comma or period among digits for the same purpose).
     410It 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).
    315411This extension is backwards compatible, matches with the use of underscore in variable names, and appears in Ada and Java.
    316412
     
    321417C declaration syntax is notoriously confusing and error prone.
    322418For example, many C programmers are confused by a declaration as simple as:
    323 \begin{quote2}
    324 \begin{tabular}{@{}ll@{}}
    325 \begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    326 int *x[ 5 ]
    327 \end{lstlisting}
    328 &
    329 \raisebox{-0.75\totalheight}{\input{Cdecl}}
    330 \end{tabular}
    331 \end{quote2}
    332 Is this an array of 5 pointers to integers or a pointer to an array of 5 integers?
     419\begin{lstlisting}
     420int *x[ 10 ]
     421\end{lstlisting}
     422Is this a pointer to an array of 10 integers or an array of 10 pointers to integers?
    333423Another 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.
    334424For example, a routine returning a pointer to an array of integers is defined and used in the following way:
    335425\begin{lstlisting}
    336 int (*f())[ 5 ] {...};  // definition mimics usage
    337 ... (*f())[ 3 ] += 1;
     426int (*f())[ 10 ] {...};
     427... (*f())[ 3 ] += 1;           // definition mimics usage
    338428\end{lstlisting}
    339429Essentially, the return type is wrapped around the routine name in successive layers (like an onion).
     
    344434The only exception is bit field specification, which always appear to the right of the base type.
    345435C and the new \CFA declarations may appear together in the same program block, but cannot be mixed within a specific declaration.
     436Unsupported are K\&R C declarations where the base type defaults to \lstinline@int@, if no type is specified\footnote{
     437At 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}},
     438e.g.:
     439\begin{lstlisting}
     440x;                                      // int x
     441*y;                                     // int *y
     442f( p1, p2 );            // int f( int p1, int p2 );
     443f( p1, p2 ) {}          // int f( int p1, int p2 ) {}
     444\end{lstlisting}
    346445
    347446In \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.
     
    352451\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    353452\begin{lstlisting}
    354 ®* int x, y;®
     453* int x, y;
    355454\end{lstlisting}
    356455&
     
    365464\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    366465\begin{lstlisting}
    367 [ 5 ] int z;
    368 [ 5 ] * char w;
    369 * [ 5 ] double v;
     466[ 10 ] int z;
     467[ 10 ] * char w;
     468* [ 10 ] double v;
    370469struct s {
    371         int f0:3;
     470int f0:3;
    372471        * int f1;
    373         [ 5 ] * int f2;
     472        [ 10 ] * int f2;
    374473};
    375474\end{lstlisting}
    376475&
    377476\begin{lstlisting}
    378 int z[ 5 ];
    379 char *w[ 5 ];
    380 double (*v)[ 5 ];
     477int z[ 10 ];
     478char *w[ 10 ];
     479double (*v)[ 10 ];
    381480struct s {
    382481        int f0:3;
    383482        int *f1;
    384         int *f2[ 5 ]
     483        int *f2[ 10 ]
    385484};
    386485\end{lstlisting}
    387486&
    388487\begin{lstlisting}
    389 // array of 5 integers
    390 // array of 5 pointers to char
    391 // pointer to array of 5 doubles
     488// array of 10 integers
     489// array of 10 pointers to char
     490// pointer to array of 10 doubles
    392491
    393492// common bit field syntax
     
    398497\end{tabular}
    399498\end{quote2}
     499
     500As stated above, the two styles of declaration may appear together in the same block.
     501Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.
     502Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX systems.
     503In general, mixing declaration styles in a routine or even a translation unit is not recommended, as it makes a program more difficult to read.
     504Therefore, it is suggested that an entire translation unit be written in one declaration style or the other.
    400505
    401506All 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.:
     
    405510\begin{lstlisting}
    406511const * const int x;
    407 const * [ 5 ] const int y;
     512const * [ 10 ] const int y;
    408513\end{lstlisting}
    409514&
    410515\begin{lstlisting}
    411516int const * const x;
    412 const int (* const y)[ 5 ]
     517const int (* const y)[ 10 ]
    413518\end{lstlisting}
    414519&
    415520\begin{lstlisting}
    416521// const pointer to const integer
    417 // const pointer to array of 5 const integers
     522// const pointer to array of 10 const integers
    418523\end{lstlisting}
    419524\end{tabular}
     
    425530\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    426531\begin{lstlisting}
    427 extern [ 5 ] int x;
     532extern [ 10 ] int x;
    428533static * const int y;
    429534\end{lstlisting}
    430535&
    431536\begin{lstlisting}
    432 int extern x[ 5 ];
     537int extern x[ 10 ];
    433538const int static *y;
    434539\end{lstlisting}
    435540&
    436541\begin{lstlisting}
    437 // externally visible array of 5 integers
     542// externally visible array of 10 integers
    438543// internally visible pointer to constant int
    439544\end{lstlisting}
    440545\end{tabular}
    441546\end{quote2}
    442 
    443 Unsupported are K\&R C declarations where the base type defaults to \lstinline@int@, if no type is specified\footnote{
    444 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}},
    445 e.g.:
    446 \begin{lstlisting}
    447 x;                                              // int x
    448 *y;                                             // int *y
    449 f( p1, p2 );                    // int f( int p1, int p2 );
    450 f( p1, p2 ) {}                  // int f( int p1, int p2 ) {}
    451 \end{lstlisting}
    452 
    453 As stated above, the two styles of declaration may appear together in the same block.
    454 Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.
    455 Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX systems.
    456547
    457548
     
    464555\begin{lstlisting}
    465556y = (* int)x;
    466 i = sizeof([ 5 ] * int);
     557i = sizeof([ 10 ] * int);
    467558\end{lstlisting}
    468559&
    469560\begin{lstlisting}
    470561y = (int *)x;
    471 i = sizeof(int *[ 5 ]);
     562i = sizeof(int *[ 10 ]);
    472563\end{lstlisting}
    473564\end{tabular}
     
    480571The point of the new syntax is to allow returning multiple values from a routine~\cite{CLU,Galletly96}, e.g.:
    481572\begin{lstlisting}
    482 ®[ int o1, int o2, char o3 ]® f( int i1, char i2, char i3 ) {
    483         §\emph{routine body}§
     573[ int o1, int o2, char o3 ] f( int i1, char i2, char i3 ) {
     574        @\emph{routine body}@
    484575}
    485576\end{lstlisting}
     
    492583Declaration qualifiers can only appear at the start of a routine definition, e.g.:
    493584\begin{lstlisting}
    494 extern [ int x ] g( int y ) {§\,§}
     585extern [ int x ] g( int y ) {}
    495586\end{lstlisting}
    496587Lastly, if there are no output parameters or input parameters, the brackets and/or parentheses must still be specified;
    497588in 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:
    498589\begin{lstlisting}
    499 [§\,§] g();                                             // no input or output parameters
     590[ ] g();                                        // no input or output parameters
    500591[ void ] g( void );                     // no input or output parameters
    501592\end{lstlisting}
     
    509600\CFA style declarations cannot be used to declare parameters for K\&R style routine definitions because of the following ambiguity:
    510601\begin{lstlisting}
    511 int (*f(x))[ 5 ] int x; {}
    512 \end{lstlisting}
    513 The 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.
     602int (*f(x))[ 10 ] int x; {}
     603\end{lstlisting}
     604The 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.
    514605Since the strings overlap starting with the open bracket, \lstinline@[@, there is an ambiguous interpretation for the string.
    515606As well, \CFA-style declarations cannot be used to declare parameters for C-style routine-definitions because of the following ambiguity:
     
    530621\begin{lstlisting}
    531622#define ptoa( n, d ) int (*n)[ d ]
    532 int f( ptoa(p,5) ) ...          // expands to int f( int (*p)[ 5 ] )
    533 [ int ] f( ptoa(p,5) ) ...      // expands to [ int ] f( int (*p)[ 5 ] )
     623int f( ptoa(p,10) ) ...         // expands to int f( int (*p)[ 10 ] )
     624[ int ] f( ptoa(p,10) ) ...     // expands to [ int ] f( int (*p)[ 10 ] )
    534625\end{lstlisting}
    535626Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    548639Because 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:
    549640\begin{lstlisting}
    550 ®[ int x ]® f() {
     641[ int x ] f() {
    551642        ... x = 0; ... x = y; ...
    552         ®return;® // implicitly return x
     643        return; // implicitly return x
    553644}
    554645\end{lstlisting}
     
    606697for example, the following is incorrect:
    607698\begin{lstlisting}
    608 * [ int x ] f () fp;            // routine name "f" is not allowed
     699* [ int x ] f () fp;            // routine name ``f'' is not allowed
    609700\end{lstlisting}
    610701
     
    612703\section{Named and Default Arguments}
    613704
    614 Named and default arguments~\cite{Hardgrave76}\footnote{
     705Named and default arguments~\cite{Hardgrave76}.\footnote{
    615706Francez~\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.}
    616707are two mechanisms to simplify routine call.
     
    773864\subsection{Type Nesting}
    774865
    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.
     866C allows \Index{type nesting}, but the nested types are hoisted\index{type!hoisting} (refactored) into the enclosing scope.
    776867\begin{quote2}
    777868\begin{tabular}{@{}l@{\hspace{30pt}}l|l@{}}
     
    828919
    829920int fred() {
    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;
     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;
    834925}
    835926\end{lstlisting}
    836927\end{tabular}
    837928\end{quote2}
    838 In 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.
    839 In 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@::@''.
     929
     930\CFA is C \emph{incompatible} on this issue, and provides semantics similar to \CC.
     931Nested types are not hoisted and can be referenced using the field selection operator ``\lstinline@.@'', unlike the \CC scope-resolution operator ``\lstinline@::@''.
     932Given 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.
    840933
    841934
     
    850943which can be used to sort in ascending and descending order by locally redefining the less-than operator into greater-than.
    851944\begin{lstlisting}
    852 const unsigned int size = 5;
    853 int ia[size];
    854 ...                                             // assign values to array ia
    855 qsort( 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 
    862 Nested routines are not first-class, meaning a nested routine cannot be returned if it has references to variables in its enclosing blocks;
    863 the only exception is references to the external block of the translation unit, as these variables persist for the duration of the program.
    864 The 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 }
    874 int main() {
    875         * [int](int) fp = foo();        // int (*fp)(int)
    876     sout | fp( 3 ) | endl;
    877 }
    878 \end{lstlisting}
    879 because
    880 
    881 Currently, there are no \Index{lambda} expressions, i.e., unnamed routines because routine names are very important to properly select the correct routine.
     945const unsigned int size = 10;
     946int a[size];
     947
     948qsort( 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
     958The following incompatibles exist between C and \CFA, and are similar to Annex C for \CC~\cite{ANSI14:C++}.
     959
     960\begin{enumerate}
     961\item
     962Change type of character literal \lstinline@int@ to \lstinline@char@.
     963This change allows overloading differentiation argument type matching, e.g.:
     964\begin{lstlisting}
     965int function( int i );
     966int function( char c );
     967function( 'x' );
     968\end{lstlisting}
     969It is preferable that this call match the second version of function rather than the first. \\
     970Effect on original feature: Change to semantics of well-defined feature. ISO C programs which depend on
     971\begin{lstlisting}
     972sizeof('x') == sizeof(int)
     973\end{lstlisting}
     974will not work the same as C++ programs. \\
     975Difficulty of converting: Simple. \\
     976How widely used: Programs which depend upon sizeof('x') are probably rare.
     977
     978\item
     979Change: String literals made \lstinline@const@ \\
     980The type of a string literal is changed from \lstinline@array of char@ to \lstinline@array of const char@.
     981The type of a wide string literal is changed from \lstinline@array of wchar_t@ to \lstinline@array of const wchar_t@. \\
     982Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument.
     983Effect on original feature: Change to semantics of well-defined feature. \\
     984Difficulty of converting: Simple syntactic transformation, because string literals can be converted to \lstinline@char*;@ (4.2).
     985The most common cases are handled by a new but deprecated standard conversion:
     986\begin{lstlisting}
     987char* p = "abc"; // valid in C, deprecated in C++
     988char* q = expr ? "abc" : "de"; // valid in C, invalid in C++
     989\end{lstlisting}
     990How widely used: Programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are probably rare.
     991
     992\item
     993Change: C++ does not have \emph{tentative definitions} as in C.
     994E.g., at file scope,
     995\begin{lstlisting}
     996int i;
     997int i;
     998\end{lstlisting}
     999is valid in C, invalid in C++.
     1000This makes it impossible to define mutually referential file-local static
     1001objects, if initializers are restricted to the syntactic forms of C. For example,
     1002\begin{lstlisting}
     1003struct X { int i; struct X *next; };
     1004static struct X a;
     1005static struct X b = { 0, &a };
     1006static struct X a = { 1, &b };
     1007\end{lstlisting}
     1008Rationale: This avoids having different initialization rules for builtin types and userdefined types.
     1009Effect on original feature: Deletion of semantically welldefined feature. \\
     1010Difficulty of converting: Semantic transformation.
     1011In C++, the initializer for one of a set of mutuallyreferential filelocal static objects must invoke a function call to achieve the initialization.
     1012How widely used: Seldom.
     1013
     1014\item
     1015Change: A struct is a scope in C++, not in C
     1016Rationale: Class scope is crucial to C++, and a struct is a class.
     1017Effect on original feature: Change to semantics of well-defined feature.
     1018Difficulty of converting: Semantic transformation.
     1019How widely used: C programs use struct extremely frequently, but the change is only noticeable when
     1020struct, enumeration, or enumerator names are referred to outside the struct. The latter is probably
     1021rare.
     1022
     1023\item
     1024Change: In C++, the name of a nested class is local to its enclosing class.
     1025In C the name of the nested class belongs to the same scope as the name of the outermost enclosing class
     1026Example:
     1027\begin{lstlisting}
     1028struct X {
     1029struct Y { /* ... */ } y;
     1030};
     1031struct Y yy; // valid C, invalid C++
     1032\end{lstlisting}
     1033Rationale: C++ classes have member functions which require that classes establish scopes. The C rule
     1034would leave classes as an incomplete scope mechanism which would prevent C++ programmers from maintaining
     1035locality within a class. A coherent set of scope rules for C++ based on the C rule would be very
     1036complicated and C++ programmers would be unable to predict reliably the meanings of nontrivial examples
     1037involving nested or local functions.
     1038Effect on original feature: Change of semantics of welldefined
     1039feature.
     1040Difficulty of converting: Semantic transformation. To make the struct type name visible in the scope of
     1041the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing
     1042struct is defined. Example:
     1043\begin{lstlisting}
     1044struct Y; // struct Y and struct X are at the same scope
     1045struct X {
     1046struct Y { /* ... */ } y;
     1047};
     1048\end{lstlisting}
     1049All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of
     1050the enclosing struct could be exported to the scope of the enclosing struct. Note: this is a consequence of
     1051the difference in scope rules, which is documented in 3.3.
     1052How widely used: Seldom.
     1053\end{enumerate}
    8821054
    8831055
     
    8891061The general syntax of a tuple is:
    8901062\begin{lstlisting}
    891 [ §\emph{exprlist}§ ]
     1063[ $\emph{exprlist}$ ]
    8921064\end{lstlisting}
    8931065where \lstinline@$\emph{exprlist}$@ is a list of one or more expressions separated by commas.
     
    9091081The general syntax of a tuple type is:
    9101082\begin{lstlisting}
    911 [ §\emph{typelist}§ ]
     1083[ @\emph{typelist}@ ]
    9121084\end{lstlisting}
    9131085where \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.
     
    9171089[ double, double, double ]
    9181090[ * int, int * ]                // mix of CFA and ANSI
    919 [ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
     1091[ * [ 10 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    9201092\end{lstlisting}
    9211093Like 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.
     
    10131185First the right-hand tuple is flattened and then the values are assigned individually.
    10141186Flattening is also performed on tuple types.
    1015 For example, the type \lstinline@[ int, [ int, int ], int ]@ can be coerced, using flattening, into the type \lstinline@[ int, int, int, int ]@.
     1187For example, the type \lstinline@[ int, [ int, int ], int ]@ can be coerced, using flattening, into the type lstinline@[ int, int, int, int ]@.
    10161188
    10171189A \newterm{structuring coercion} is the opposite of flattening;
     
    10391211Mass assignment has the following form:
    10401212\begin{lstlisting}
    1041 [ §\emph{lvalue}§, ..., §\emph{lvalue}§ ] = §\emph{expr}§;
    1042 \end{lstlisting}
    1043 The left-hand side is a tuple of \emph{lvalues}, which is a list of expressions each yielding an address, i.e., any data object that can appear on the left-hand side of a conventional assignment statement.
     1213[ @\emph{lvalue}@, ..., @\emph{lvalue}@ ] = @\emph{expr}@;
     1214\end{lstlisting}
     1215The 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.
    10441216\lstinline@$\emph{expr}$@ is any standard arithmetic expression.
    10451217Clearly, the types of the entities being assigned must be type compatible with the value of the expression.
     
    10781250Multiple assignment has the following form:
    10791251\begin{lstlisting}
    1080 [ §\emph{lvalue}§, . . ., §\emph{lvalue}§ ] = [ §\emph{expr}§, . . ., §\emph{expr}§ ];
    1081 \end{lstlisting}
    1082 The left-hand side is a tuple of \emph{lvalues}, and the right-hand side is a tuple of \emph{expr}s.
    1083 Each \emph{expr} appearing on the righthand side of a multiple assignment statement is assigned to the corresponding \emph{lvalues} on the left-hand side of the statement using parallel semantics for each assignment.
     1252[ @\emph{lvalue}@, . . ., @\emph{lvalue}@ ] = [ @\emph{expr}@, . . ., @\emph{expr}@ ];
     1253\end{lstlisting}
     1254The left-hand side is a tuple of \lstinline@$\emph{lvalues}$@, and the right-hand side is a tuple of \lstinline@$\emph{expr}$@s.
     1255Each \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.
    10841256An example of multiple assignment is:
    10851257\begin{lstlisting}
     
    11181290Cascade assignment has the following form:
    11191291\begin{lstlisting}
    1120 §\emph{tuple}§ = §\emph{tuple}§ = ... = §\emph{tuple}§;
     1292@\emph{tuple}@ = @\emph{tuple}@ = ... = @\emph{tuple}@;
    11211293\end{lstlisting}
    11221294and it has the same parallel semantics as for mass and multiple assignment.
     
    11361308Its general form is:
    11371309\begin{lstlisting}
    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@.
    1142 Each element of \emph{ fieldlist} is an element of the record specified by \emph{expr}.
     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@.
     1314Each element of \lstinline@$\emph{ fieldlist}$@ is an element of the record specified by \lstinline@$\emph{expr}$@.
    11431315A record-field tuple may be used anywhere a tuple can be used. An example of the use of a record-field tuple is
    11441316the following:
     
    11801352\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    11811353\begin{lstlisting}
    1182 ®L1:® for ( ... ) {
    1183         ®L2:® for ( ... ) {
    1184                 ®L3:® for ( ... ) {
    1185                         ... break ®L1®; ...
    1186                         ... break ®L2®; ...
    1187                         ... break ®L3®; // or break
     1354L1: for ( ... ) {
     1355        L2: for ( ... ) {
     1356                L3: for ( ... ) {
     1357                        ... break L1; ...
     1358                        ... break L2; ...
     1359                        ... break L3; // or break
    11881360                }
    11891361        }
     
    12101382\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    12111383\begin{lstlisting}
    1212 ®L1®: for ( ... ) {
    1213         ®L2®: for ( ... ) {
    1214                 ®L3®: for ( ... ) {
    1215                         ... continue ®L1®; ...
    1216                         ... continue ®L2®; ...
    1217                         ... continue ®L3®; ...
     1384L1: for ( ... ) {
     1385        L2: for ( ... ) {
     1386                L3: for ( ... ) {
     1387                        ... continue L1; ...
     1388                        ... continue L2; ...
     1389                        ... continue L3; ...
    12181390
    12191391                }
     
    14511623\begin{lstlisting}
    14521624switch ( i ) {
    1453   ®case 1, 3, 5®:
     1625  case 1, 3, 5:
    14541626        ...
    1455   ®case 2, 4, 6®:
     1627  case 2, 4, 6:
    14561628        ...
    14571629}
     
    14621634  case 1: case 3 : case 5:
    14631635        ...
    1464   case 2: case 4 : case 6:
     1636  case 2: case 4 : case 6: /* even values */
    14651637        ...
    14661638}
     
    14831655\begin{lstlisting}
    14841656switch ( i ) {
    1485   ®case 1~5:®
     1657  case 1~5
    14861658        ...
    1487   ®case 10~15:®
     1659  case 10~15
    14881660        ...
    14891661}
     
    15001672&
    15011673\begin{lstlisting}
    1502 
    15031674// 1, 2, 3, 4, 5
    15041675
     
    19972168
    19982169
    1999 \section{Auto Type-Inferencing}
    2000 
    2001 Auto 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 
    2007 auto j = 3.0 * 4;
    2008 int i;
    2009 auto k = i;
    2010 \end{lstlisting}
    2011 &
    2012 \begin{lstlisting}
    2013 #define expr 3.0 * i
    2014 typeof(expr) j = expr;
    2015 int i;
    2016 typeof(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}
    2027 The two important capabilities are:
    2028 \begin{itemize}
    2029 \item
    2030 preventing having to determine or write out long generic types,
    2031 \item
    2032 ensure secondary variables, related to a primary variable, always have the same type.
    2033 \end{itemize}
    2034 
    2035 In \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.
    2038 Only for overloaded routines with the same return type is variable type-inferencing possible.
    2039 Finally, \lstinline@auto@ presents the programming problem of tracking down a type when the type is actually needed.
    2040 For example, given
    2041 \begin{lstlisting}
    2042 auto j = ®...®
    2043 \end{lstlisting}
    2044 and the need to write a routine to compute using \lstinline@j@
    2045 \begin{lstlisting}
    2046 void rtn( ®...® parm );
    2047 rtn( j );
    2048 \end{lstlisting}
    2049 A programmer must work backwards to determine the type of \lstinline@j@'s initialization expression, reconstructing the possibly long generic type-name.
    2050 In this situation, having the type name or a short alias is very useful.
    2051 
    2052 There is also the conundrum in type inferencing of when to \emph{\Index{brand}} a type.
    2053 That is, when is the type of the variable more important than the type of its initialization expression.
    2054 For example, if a change is made in an initialization expression, it can cause hundreds or thousands of cascading type changes and/or errors.
    2055 At some point, a programmer wants the type of the variable to remain constant and the expression to be in error when it changes.
    2056 
    2057 Given \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.
    2058 Should a significant need arise, this feature can be revisited.
    2059 
    2060 
    2061 \section{Generics}
     2170\section{Generics }
    20622171
    20632172\CFA supports parametric polymorphism to allow users to define generic functions and types.
     
    22592368
    22602369        try {
    2261                 throw 13;
     2370        throw 13;
    22622371        }
    22632372        catch(int e) {
    2264                 printf(.caught an exception: %d\n., e);
     2373        printf(.caught an exception: %d\n., e);
    22652374        }
    22662375\end{lstlisting}
     
    23482457
    23492458
    2350 \section{Syntactic Anomalies}
    2351 
    2352 The number 0 and 1 are treated specially in \CFA, and can be redefined as variables.
    2353 One syntactic anomaly is when a field in an structure is names 0 or 1:
    2354 \begin{lstlisting}
    2355 struct S {
    2356         int 0, 1;
    2357 } s;
    2358 \end{lstlisting}
    2359 The problem occurs in accesing these fields using the selection operation ``\lstinline@.@'':
    2360 \begin{lstlisting}
    2361 s.0 = 0;        // ambiguity with floating constant .0
    2362 s.1 = 1;        // ambiguity with floating constant .1
    2363 \end{lstlisting}
    2364 To 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}
    2369 While this sytact is awkward, it is unlikely many programers will name fields of a structure 0 or 1.
    2370 Like 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 
    2372 There are several ambiguous cases with operator identifiers, e.g., \lstinline@int *?*?()@, where the string \lstinline@*?*?@ can be lexed as \lstinline@*@/\lstinline@?*?@ or \lstinline@*?@/\lstinline@*?@.
    2373 Since 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.
    2374 Even with this special hack, there are 5 general cases that cannot be handled.
    2375 The first case is for the function-call identifier \lstinline@?()@:
    2376 \begin{lstlisting}
    2377 int *§\textvisiblespace§?()();  // declaration: space required after '*'
    2378 *§\textvisiblespace§?()();              // expression: space required after '*'
    2379 \end{lstlisting}
    2380 Without the space, the string \lstinline@*?()@ is ambiguous without N character look ahead;
    2381 it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument/parameter list.
    2382 
    2383 The 4 remaining cases occur in expressions:
    2384 \begin{lstlisting}
    2385 i++§\textvisiblespace§?i:0;             // space required before '?'
    2386 i--§\textvisiblespace§?i:0;             // space required before '?'
    2387 i§\textvisiblespace§?++i:0;             // space required after '?'
    2388 i§\textvisiblespace§?--i:0;             // space required after '?'
    2389 \end{lstlisting}
    2390 In the first two cases, the string \lstinline@i++?@ is ambiguous, where this string can be lexed as \lstinline@i@ / \lstinline@++?@ or \lstinline@i++@ / \lstinline@?@;
    2391 it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list.
    2392 In 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@;
    2393 it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list.
     2459\section{I/O Library}
     2460\label{s:IOLibrary}
     2461
     2462The 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.
     2463The general case is printing out a sequence of variables separated by whitespace.
     2464\begin{lstlisting}
     2465int x = 0, y = 1, z = 2;
     2466sout | x | y | z | endl;
     2467
     2468cout << x << " " << y << " " << z << endl;
     2469\end{lstlisting}
     2470The \CC form takes almost twice as many characters.
     2471
     2472The logical-or operator is used because it is the lowest priority overloadable operator, other than assignment.
     2473Therefore, most output expressions do not require parenthesis.
     2474\begin{lstlisting}
     2475int x = 0, y = 1, z = 2;
     2476sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     2477
     2478cout << x * 3 << y + 1 << (z << 2) << (x == y) << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
     2479\end{lstlisting}
     2480
     2481Finally, 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
     2487int 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
     2526A 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
     2528A
     25291 2 3 4 5 6 7 8
     25301.1 1.2 1.3
     25311.11.21.3
     25321.1+2.3i, $1.1-2.3i, $1.1-2.3i
     2533, $abcxyz
     2534abcxyz
     2535\end{lstlisting}
     2536\end{figure}
     2537
     2538
     2539\section{Standard Library}
     2540\label{s:StandardLibrary}
     2541
     2542The 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}
     2548forall( otype T ) T * malloc( void );
     2549forall( otype T ) T * malloc( char fill );
     2550forall( otype T ) T * malloc( T * ptr, size_t size );
     2551forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
     2552forall( otype T ) T * calloc( size_t size );
     2553forall( otype T ) T * realloc( T * ptr, size_t size );
     2554forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
     2555
     2556forall( otype T ) T * aligned_alloc( size_t alignment );
     2557forall( otype T ) T * memalign( size_t alignment );             // deprecated
     2558forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
     2559
     2560forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
     2561forall( otype T ) T * memset( T * ptr );                                // remove when default value available
     2562\end{lstlisting}
     2563
     2564
     2565\subsection{ato/strto}
     2566
     2567\begin{lstlisting}
     2568int ato( const char * ptr );
     2569unsigned int ato( const char * ptr );
     2570long int ato( const char * ptr );
     2571unsigned long int ato( const char * ptr );
     2572long long int ato( const char * ptr );
     2573unsigned long long int ato( const char * ptr );
     2574float ato( const char * ptr );
     2575double ato( const char * ptr );
     2576long double ato( const char * ptr );
     2577float _Complex ato( const char * ptr );
     2578double _Complex ato( const char * ptr );
     2579long double _Complex ato( const char * ptr );
     2580
     2581int strto( const char * sptr, char ** eptr, int base );
     2582unsigned int strto( const char * sptr, char ** eptr, int base );
     2583long int strto( const char * sptr, char ** eptr, int base );
     2584unsigned long int strto( const char * sptr, char ** eptr, int base );
     2585long long int strto( const char * sptr, char ** eptr, int base );
     2586unsigned long long int strto( const char * sptr, char ** eptr, int base );
     2587float strto( const char * sptr, char ** eptr );
     2588double strto( const char * sptr, char ** eptr );
     2589long double strto( const char * sptr, char ** eptr );
     2590float _Complex strto( const char * sptr, char ** eptr );
     2591double _Complex strto( const char * sptr, char ** eptr );
     2592long double _Complex strto( const char * sptr, char ** eptr );
     2593\end{lstlisting}
     2594
     2595
     2596\subsection{bsearch/qsort}
     2597
     2598\begin{lstlisting}
     2599forall( otype T | { int ?<?( T, T ); } )
     2600T * bsearch( const T key, const T * arr, size_t dimension );
     2601
     2602forall( otype T | { int ?<?( T, T ); } )
     2603void qsort( const T * arr, size_t dimension );
     2604\end{lstlisting}
     2605
     2606
     2607\subsection{abs}
     2608
     2609\begin{lstlisting}
     2610char abs( char );
     2611extern "C" {
     2612int abs( int );         // use default C routine for int
     2613} // extern
     2614long int abs( long int );
     2615long long int abs( long long int );
     2616float abs( float );
     2617double abs( double );
     2618long double abs( long double );
     2619float _Complex abs( float _Complex );
     2620double _Complex abs( double _Complex );
     2621long double _Complex abs( long double _Complex );
     2622\end{lstlisting}
     2623
     2624
     2625\subsection{random}
     2626
     2627\begin{lstlisting}
     2628void randseed( long int s );
     2629char random();
     2630int random();
     2631unsigned int random();
     2632long int random();
     2633unsigned long int random();
     2634float random();
     2635double random();
     2636float _Complex random();
     2637double _Complex random();
     2638long double _Complex random();
     2639\end{lstlisting}
     2640
     2641
     2642\subsection{min/max/swap}
     2643
     2644\begin{lstlisting}
     2645forall( otype T | { int ?<?( T, T ); } )
     2646T min( const T t1, const T t2 );
     2647
     2648forall( otype T | { int ?>?( T, T ); } )
     2649T max( const T t1, const T t2 );
     2650
     2651forall( otype T )
     2652void swap( T * t1, T * t2 );
     2653\end{lstlisting}
    23942654
    23952655
     
    24162676
    24172677task creates a type with implicit locking, separate stack, and a thread
    2418 
    24192678
    24202679\subsection{Monitors}
     
    33173576
    33183577
    3319 \subsection[Comparing Key Features of CFA]{Comparing Key Features of \CFA}
     3578\subsection{Comparing Key Features of \CFA}
    33203579
    33213580
     
    35163775\multicolumn{1}{c|}{\textbf{\CFA/\CC}} & \multicolumn{1}{c|}{\textbf{Go}} & \multicolumn{1}{c}{\textbf{Rust}}   \\
    35173776\hline
    3518 \begin{lstlisting}[boxpos=t]
     3777\begin{lstlisting}
    35193778extern "C" {
    35203779#include <sys/types.h>
     
    35233782}
    35243783size_t fileSize( const char *path ) {
    3525         struct stat s;
     3784        stat s;
    35263785        stat(path, &s);
    35273786        return s.st_size;
     
    35293788\end{lstlisting}
    35303789&
    3531 \begin{lstlisting}[boxpos=t]
     3790\begin{lstlisting}
    35323791/*
    35333792#cgo
     
    35483807\end{lstlisting}
    35493808&
    3550 \begin{lstlisting}[boxpos=t]
     3809\begin{lstlisting}
    35513810use libc::{c_int, size_t};
     3811
     3812// The following declarations are
    35523813// translated from sys/stat.h
    35533814#[repr(C)]
     
    35573818        ...
    35583819}
     3820
    35593821#[link(name = "libc")]
    35603822extern {
     
    35623824        buf: *mut stat_t) -> c_int;
    35633825}
     3826
    35643827fn fileSize(path: *const u8) -> size_t
    35653828{
    35663829        unsafe {
    3567                 let mut buf: stat_t = uninit();
    3568                 stat(path, &mut buf);
    3569                 buf.st_size
     3830        let mut buf: stat_t = uninit();
     3831        stat(path, &mut buf);
     3832        buf.st_size
    35703833        }
    35713834}
     
    36903953
    36913954
    3692 \begin{comment}
    3693 \subsubsection{Modules / Packages}
     3955\subsubsection{Modules/Packages}
    36943956
    36953957\begin{lstlisting}
     
    37704032}
    37714033\end{lstlisting}
    3772 \end{comment}
    3773 
    37744034
    37754035\subsubsection{Parallel Tasks}
     
    39274187\end{flushleft}
    39284188
    3929 \lstset{basicstyle=\sf\relsize{-1}}
    3930 
    3931 
    39324189\subsection{Summary of Language Comparison}
    39334190
    39344191
    3935 \subsubsection[C++]{\CC}
     4192\subsubsection{\CC}
    39364193
    39374194\CC is a general-purpose programming language.
     
    39984255
    39994256
    4000 \appendix
    4001 
    4002 
    4003 \section{Incompatible}
    4004 
    4005 The following incompatibles exist between C and \CFA, and are similar to Annex C for \CC~\cite{ANSI14:C++}.
    4006 
    4007 \begin{enumerate}
    4008 \item
    4009 Change type of character literal \lstinline@int@ to \lstinline@char@.
    4010 This change allows overloading differentiation argument type matching, e.g.:
    4011 \begin{lstlisting}
    4012 int function( int i );
    4013 int function( char c );
    4014 function( 'x' );
    4015 \end{lstlisting}
    4016 It is preferable that this call match the second version of function rather than the first. \\
    4017 Effect on original feature: Change to semantics of well-defined feature. ISO C programs which depend on
    4018 \begin{lstlisting}
    4019 sizeof('x') == sizeof(int)
    4020 \end{lstlisting}
    4021 will not work the same as C++ programs. \\
    4022 Difficulty of converting: Simple. \\
    4023 How widely used: Programs which depend upon sizeof('x') are probably rare.
    4024 
    4025 \item
    4026 Change: String literals made \lstinline@const@ \\
    4027 The type of a string literal is changed from \lstinline@array of char@ to \lstinline@array of const char@.
    4028 The type of a wide string literal is changed from \lstinline@array of wchar_t@ to \lstinline@array of const wchar_t@. \\
    4029 Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument.
    4030 Effect on original feature: Change to semantics of well-defined feature. \\
    4031 Difficulty of converting: Simple syntactic transformation, because string literals can be converted to \lstinline@char*;@ (4.2).
    4032 The most common cases are handled by a new but deprecated standard conversion:
    4033 \begin{lstlisting}
    4034 char* p = "abc"; // valid in C, deprecated in C++
    4035 char* q = expr ? "abc" : "de"; // valid in C, invalid in C++
    4036 \end{lstlisting}
    4037 How widely used: Programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are probably rare.
    4038 
    4039 \item
    4040 Change: C++ does not have \emph{tentative definitions} as in C.
    4041 E.g., at file scope,
    4042 \begin{lstlisting}
    4043 int i;
    4044 int i;
    4045 \end{lstlisting}
    4046 is valid in C, invalid in C++.
    4047 This makes it impossible to define mutually referential file-local static
    4048 objects, if initializers are restricted to the syntactic forms of C. For example,
    4049 \begin{lstlisting}
    4050 struct X { int i; struct X *next; };
    4051 static struct X a;
    4052 static struct X b = { 0, &a };
    4053 static struct X a = { 1, &b };
    4054 \end{lstlisting}
    4055 Rationale: This avoids having different initialization rules for builtin types and userdefined types.
    4056 Effect on original feature: Deletion of semantically welldefined feature. \\
    4057 Difficulty of converting: Semantic transformation.
    4058 In C++, the initializer for one of a set of mutuallyreferential filelocal static objects must invoke a function call to achieve the initialization.
    4059 How widely used: Seldom.
    4060 
    4061 \item
    4062 Change: A struct is a scope in C++, not in C \\
    4063 Rationale: Class scope is crucial to C++, and a struct is a class. \\
    4064 Effect on original feature: Change to semantics of well-defined feature. \\
    4065 Difficulty of converting: Semantic transformation. \\
    4066 How 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.
    4067 The latter is probably rare.
    4068 
    4069 \CFA is C \emph{incompatible} on this issue, and provides semantics similar to \CC.
    4070 Nested types are not hoisted and can be referenced using the field selection operator ``\lstinline@.@'', unlike the \CC scope-resolution operator ``\lstinline@::@''.
    4071 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.
    4072 
    4073 \item
    4074 Change: In C++, the name of a nested class is local to its enclosing class.
    4075 In C the name of the nested class belongs to the same scope as the name of the outermost enclosing class
    4076 Example:
    4077 \begin{lstlisting}
    4078 struct X {
    4079 struct Y { /* ... */ } y;
    4080 };
    4081 struct Y yy; // valid C, invalid C++
    4082 \end{lstlisting}
    4083 Rationale: C++ classes have member functions which require that classes establish scopes.
    4084 The 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.
    4085 Effect on original feature: Change of semantics of welldefined feature.
    4086 Difficulty of converting: Semantic transformation. To make the struct type name visible in the scope of the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing struct is defined. Example:
    4087 \begin{lstlisting}
    4088 struct Y; // struct Y and struct X are at the same scope
    4089 struct X {
    4090 struct Y { /* ... */ } y;
    4091 };
    4092 \end{lstlisting}
    4093 All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of the enclosing struct could be exported to the scope of the enclosing struct.
    4094 Note: this is a consequence of the difference in scope rules, which is documented in 3.3.
    4095 How widely used: Seldom.
    4096 \end{enumerate}
    4097 
    4098 
    4099 \section{I/O Library}
    4100 \label{s:IOLibrary}
    4101 \index{input/output library}
    4102 
    4103 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.
    4104 The 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}
    4109 int x = 0, y = 1, z = 2;
    4110 ®sout® ®|® x ®|® y ®|® z ®| endl®;
    4111 \end{lstlisting}
    4112 &
    4113 \begin{lstlisting}
    4114 
    4115 cout << x << " " << y << " " << z << endl;
    4116 \end{lstlisting}
    4117 \end{tabular}
    4118 \end{quote2}
    4119 The \CFA form is half as many characters, and is similar to \Index{Python} I/O with respect to implicit separators.
    4120 
    4121 The logical-or operator is used because it is the lowest-priority overloadable operator, other than assignment.
    4122 Therefore, fewer output expressions require parenthesis.
    4123 \begin{quote2}
    4124 \begin{tabular}{@{}ll@{}}
    4125 \textbf{\CFA:}
    4126 &
    4127 \begin{lstlisting}
    4128 sout | 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}
    4134 cout << 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}
    4138 Finally, the logical-or operator has a link with the Shell pipe-operator for moving data, although data flows in the opposite direction.
    4139 
    4140 The implicit seperator\index{I/O separator} character (space/blank) is a separator not a terminator.
    4141 The rules for implicitly adding the separator are:
    4142 \begin{enumerate}
    4143 \item
    4144 A seperator does not appear at the start or end of a line.
    4145 \begin{lstlisting}[belowskip=0pt]
    4146 sout | 1 | 2 | 3 | endl;
    4147 \end{lstlisting}
    4148 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    4149 1 2 3
    4150 \end{lstlisting}
    4151 \item
    4152 A seperator does not appear before or after a character literal or variable.
    4153 \begin{lstlisting}
    4154 sout | '1' | '2' | '3' | endl;
    4155 123
    4156 \end{lstlisting}
    4157 \item
    4158 A seperator does not appear before or after a null (empty) C string
    4159 \begin{lstlisting}
    4160 sout | 1 | "" | 2 | "" | 3 | endl;
    4161 123
    4162 \end{lstlisting}
    4163 which is a local mechanism to disable insertion of the separator character.
    4164 \item
    4165 A 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]
    4168 sout | "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]
    4172 x (1 x [2 x {3 x $4 x £5 x ¥6 x ¡7 x ¿8 x «9
    4173 \end{lstlisting}
    4174 %$
    4175 \item
    4176 A seperator does not appear after a C string ending with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline@,.:;!?)]}%¢»@
    4177 \begin{lstlisting}[belowskip=0pt]
    4178 sout | 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]
    4182 1, 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
    4185 A seperator does not appear before or after a C string begining/ending with the \Index{ASCII} quote or whitespace characters: \lstinline[showspaces=true]@`'" \t\v\f\r\n@
    4186 \begin{lstlisting}[belowskip=0pt]
    4187 sout | "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]
    4190 x`1`x'2'x"3"x x 4 x x   1       x
    4191 \end{lstlisting}
    4192 \end{enumerate}
    4193 The following \CC-style \Index{manipulator}s allow further control over implicit seperation.
    4194 \begin{lstlisting}[mathescape=off,belowskip=0pt]
    4195 sout | 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]
    4201 sout | 1 | sepOff | 2 | 3 | endl;                       // turn off implicit separator temporarily
    4202 \end{lstlisting}
    4203 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    4204 12 3
    4205 \end{lstlisting}
    4206 \begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    4207 sout | 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]
    4210 123
    4211 \end{lstlisting}
    4212 \begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    4213 sout | 1 | sepOn | 2 | 3 | endl;                        // turn on implicit separator temporarily
    4214 \end{lstlisting}
    4215 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    4216 1 23
    4217 \end{lstlisting}
    4218 \begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    4219 sout | 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]
    4225 sepSet( sout, ", $" );                                          // change separator from " " to ", $"
    4226 sout | 1 | 2 | 3 | endl;
    4227 \end{lstlisting}
    4228 %$
    4229 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt]
    4230 1, $2, $3
    4231 \end{lstlisting}
    4232 %$
    4233 \begin{comment}
    4234 #include <fstream>
    4235 
    4236 int 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 
    4266 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.
    4267 
    4268 
    4269 \subsection{malloc}
    4270 
    4271 \begin{lstlisting}
    4272 forall( otype T ) T * malloc( void );§\indexc{malloc}§
    4273 forall( otype T ) T * malloc( char fill );
    4274 forall( otype T ) T * malloc( T * ptr, size_t size );
    4275 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
    4276 forall( otype T ) T * calloc( size_t nmemb );§\indexc{calloc}§
    4277 forall( otype T ) T * realloc( T * ptr, size_t size );§\indexc{ato}§
    4278 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
    4279 
    4280 forall( otype T ) T * aligned_alloc( size_t alignment );§\indexc{ato}§
    4281 forall( otype T ) T * memalign( size_t alignment );             // deprecated
    4282 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
    4283 
    4284 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
    4285 forall( otype T ) T * memset( T * ptr );                                // remove when default value available
    4286 \end{lstlisting}
    4287 
    4288 
    4289 \subsection{ato / strto}
    4290 
    4291 \begin{lstlisting}
    4292 int ato( const char * ptr );§\indexc{ato}§
    4293 unsigned int ato( const char * ptr );
    4294 long int ato( const char * ptr );
    4295 unsigned long int ato( const char * ptr );
    4296 long long int ato( const char * ptr );
    4297 unsigned long long int ato( const char * ptr );
    4298 float ato( const char * ptr );
    4299 double ato( const char * ptr );
    4300 long double ato( const char * ptr );
    4301 float _Complex ato( const char * ptr );
    4302 double _Complex ato( const char * ptr );
    4303 long double _Complex ato( const char * ptr );
    4304 
    4305 int strto( const char * sptr, char ** eptr, int base );
    4306 unsigned int strto( const char * sptr, char ** eptr, int base );
    4307 long int strto( const char * sptr, char ** eptr, int base );
    4308 unsigned long int strto( const char * sptr, char ** eptr, int base );
    4309 long long int strto( const char * sptr, char ** eptr, int base );
    4310 unsigned long long int strto( const char * sptr, char ** eptr, int base );
    4311 float strto( const char * sptr, char ** eptr );
    4312 double strto( const char * sptr, char ** eptr );
    4313 long double strto( const char * sptr, char ** eptr );
    4314 float _Complex strto( const char * sptr, char ** eptr );
    4315 double _Complex strto( const char * sptr, char ** eptr );
    4316 long double _Complex strto( const char * sptr, char ** eptr );
    4317 \end{lstlisting}
    4318 
    4319 
    4320 \subsection{bsearch / qsort}
    4321 
    4322 \begin{lstlisting}
    4323 forall( otype T | { int ?<?( T, T ); } )
    4324 T * bsearch( const T key, const T * arr, size_t dimension );§\indexc{bsearch}§
    4325 
    4326 forall( otype T | { int ?<?( T, T ); } )
    4327 void qsort( const T * arr, size_t dimension );§\indexc{qsort}§
    4328 \end{lstlisting}
    4329 
    4330 
    4331 \subsection{abs}
    4332 
    4333 \begin{lstlisting}
    4334 char abs( char );§\indexc{abs}§
    4335 int abs( int );
    4336 long int abs( long int );
    4337 long long int abs( long long int );
    4338 float abs( float );
    4339 double abs( double );
    4340 long double abs( long double );
    4341 float abs( float _Complex );
    4342 double abs( double _Complex );
    4343 long double abs( long double _Complex );
    4344 \end{lstlisting}
    4345 
    4346 
    4347 \subsection{random}
    4348 
    4349 \begin{lstlisting}
    4350 void rand48seed( long int s );§\indexc{rand48seed}§
    4351 char rand48();§\indexc{rand48}§
    4352 int rand48();
    4353 unsigned int rand48();
    4354 long int rand48();
    4355 unsigned long int rand48();
    4356 float rand48();
    4357 double rand48();
    4358 float _Complex rand48();
    4359 double _Complex rand48();
    4360 long double _Complex rand48();
    4361 \end{lstlisting}
    4362 
    4363 
    4364 \subsection{min / max / swap}
    4365 
    4366 \begin{lstlisting}
    4367 forall( otype T | { int ?<?( T, T ); } )
    4368 T min( const T t1, const T t2 );§\indexc{min}§
    4369 
    4370 forall( otype T | { int ?>?( T, T ); } )
    4371 T max( const T t1, const T t2 );§\indexc{max}§
    4372 
    4373 forall( otype T )
    4374 void swap( T * t1, T * t2 );§\indexc{swap}§
    4375 \end{lstlisting}
    4376 
    4377 
    4378 \section{Math Library}
    4379 \label{s:Math Library}
    4380 
    4381 The goal of the \CFA math-library is to wrap many of the existing C math library-routines that are explicitly polymorphic into implicitly polymorphic versions.
    4382 
    4383 
    4384 \subsection{General}
    4385 
    4386 \begin{lstlisting}
    4387 float fabs( float );§\indexc{fabs}§
    4388 double fabs( double );
    4389 long double fabs( long double );
    4390 float cabs( float _Complex );
    4391 double cabs( double _Complex );
    4392 long double cabs( long double _Complex );
    4393 
    4394 float ?%?( float, float );§\indexc{fmod}§
    4395 float fmod( float, float );
    4396 double ?%?( double, double );
    4397 double fmod( double, double );
    4398 long double ?%?( long double, long double );
    4399 long double fmod( long double, long double );
    4400 
    4401 float remainder( float, float );§\indexc{remainder}§
    4402 double remainder( double, double );
    4403 long double remainder( long double, long double );
    4404 
    4405 [ int, float ] remquo( float, float );§\indexc{remquo}§
    4406 float remquo( float, float, int * );
    4407 [ int, double ] remquo( double, double );
    4408 double remquo( double, double, int * );
    4409 [ int, long double ] remquo( long double, long double );
    4410 long double remquo( long double, long double, int * );
    4411 
    4412 [ int, float ] div( float, float );                                             // alternative name for remquo
    4413 float div( float, float, int * );§\indexc{div}§
    4414 [ int, double ] div( double, double );
    4415 double div( double, double, int * );
    4416 [ int, long double ] div( long double, long double );
    4417 long double div( long double, long double, int * );
    4418 
    4419 float fma( float, float, float );§\indexc{fma}§
    4420 double fma( double, double, double );
    4421 long double fma( long double, long double, long double );
    4422 
    4423 float fdim( float, float );§\indexc{fdim}§
    4424 double fdim( double, double );
    4425 long double fdim( long double, long double );
    4426 
    4427 float nan( const char * );§\indexc{nan}§
    4428 double nan( const char * );
    4429 long double nan( const char * );
    4430 \end{lstlisting}
    4431 
    4432 
    4433 \subsection{Exponential}
    4434 
    4435 \begin{lstlisting}
    4436 float exp( float );§\indexc{exp}§
    4437 double exp( double );
    4438 long double exp( long double );
    4439 float _Complex exp( float _Complex );
    4440 double _Complex exp( double _Complex );
    4441 long double _Complex exp( long double _Complex );
    4442 
    4443 float exp2( float );§\indexc{exp2}§
    4444 double exp2( double );
    4445 long double exp2( long double );
    4446 float _Complex exp2( float _Complex );
    4447 double _Complex exp2( double _Complex );
    4448 long double _Complex exp2( long double _Complex );
    4449 
    4450 float expm1( float );§\indexc{expm1}§
    4451 double expm1( double );
    4452 long double expm1( long double );
    4453 
    4454 float log( float );§\indexc{log}§
    4455 double log( double );
    4456 long double log( long double );
    4457 float _Complex log( float _Complex );
    4458 double _Complex log( double _Complex );
    4459 long double _Complex log( long double _Complex );
    4460 
    4461 float log2( float );§\indexc{log2}§
    4462 double log2( double );
    4463 long double log2( long double );
    4464 float _Complex log2( float _Complex );
    4465 double _Complex log2( double _Complex );
    4466 long double _Complex log2( long double _Complex );
    4467 
    4468 float log10( float );§\indexc{log10}§
    4469 double log10( double );
    4470 long double log10( long double );
    4471 float _Complex log10( float _Complex );
    4472 double _Complex log10( double _Complex );
    4473 long double _Complex log10( long double _Complex );
    4474 
    4475 float log1p( float );§\indexc{log1p}§
    4476 double log1p( double );
    4477 long double log1p( long double );
    4478 
    4479 int ilogb( float );§\indexc{ilogb}§
    4480 int ilogb( double );
    4481 int ilogb( long double );
    4482 
    4483 float logb( float );§\indexc{logb}§
    4484 double logb( double );
    4485 long double logb( long double );
    4486 \end{lstlisting}
    4487 
    4488 
    4489 \subsection{Power}
    4490 
    4491 \begin{lstlisting}
    4492 float sqrt( float );§\indexc{sqrt}§
    4493 double sqrt( double );
    4494 long double sqrt( long double );
    4495 float _Complex sqrt( float _Complex );
    4496 double _Complex sqrt( double _Complex );
    4497 long double _Complex sqrt( long double _Complex );
    4498 
    4499 float cbrt( float );§\indexc{cbrt}§
    4500 double cbrt( double );
    4501 long double cbrt( long double );
    4502 
    4503 float hypot( float, float );§\indexc{hypot}§
    4504 double hypot( double, double );
    4505 long double hypot( long double, long double );
    4506 
    4507 float pow( float, float );§\indexc{pow}§
    4508 double pow( double, double );
    4509 long double pow( long double, long double );
    4510 float _Complex pow( float _Complex, float _Complex );
    4511 double _Complex pow( double _Complex, double _Complex );
    4512 long double _Complex pow( long double _Complex, long double _Complex );
    4513 \end{lstlisting}
    4514 
    4515 
    4516 \subsection{Trigonometric}
    4517 
    4518 \begin{lstlisting}
    4519 float sin( float );§\indexc{sin}§
    4520 double sin( double );
    4521 long double sin( long double );
    4522 float _Complex sin( float _Complex );
    4523 double _Complex sin( double _Complex );
    4524 long double _Complex sin( long double _Complex );
    4525 
    4526 float cos( float );§\indexc{cos}§
    4527 double cos( double );
    4528 long double cos( long double );
    4529 float _Complex cos( float _Complex );
    4530 double _Complex cos( double _Complex );
    4531 long double _Complex cos( long double _Complex );
    4532 
    4533 float tan( float );§\indexc{tan}§
    4534 double tan( double );
    4535 long double tan( long double );
    4536 float _Complex tan( float _Complex );
    4537 double _Complex tan( double _Complex );
    4538 long double _Complex tan( long double _Complex );
    4539 
    4540 float asin( float );§\indexc{asin}§
    4541 double asin( double );
    4542 long double asin( long double );
    4543 float _Complex asin( float _Complex );
    4544 double _Complex asin( double _Complex );
    4545 long double _Complex asin( long double _Complex );
    4546 
    4547 float acos( float );§\indexc{acos}§
    4548 double acos( double );
    4549 long double acos( long double );
    4550 float _Complex acos( float _Complex );
    4551 double _Complex acos( double _Complex );
    4552 long double _Complex acos( long double _Complex );
    4553 
    4554 float atan( float );§\indexc{atan}§
    4555 double atan( double );
    4556 long double atan( long double );
    4557 float _Complex atan( float _Complex );
    4558 double _Complex atan( double _Complex );
    4559 long double _Complex atan( long double _Complex );
    4560 
    4561 float atan2( float, float );§\indexc{atan2}§
    4562 double atan2( double, double );
    4563 long double atan2( long double, long double );
    4564 
    4565 float atan( float, float );                                                             // alternative name for atan2
    4566 double atan( double, double );§\indexc{atan}§
    4567 long double atan( long double, long double );
    4568 \end{lstlisting}
    4569 
    4570 
    4571 \subsection{Hyperbolic}
    4572 
    4573 \begin{lstlisting}
    4574 float sinh( float );§\indexc{sinh}§
    4575 double sinh( double );
    4576 long double sinh( long double );
    4577 float _Complex sinh( float _Complex );
    4578 double _Complex sinh( double _Complex );
    4579 long double _Complex sinh( long double _Complex );
    4580 
    4581 float cosh( float );§\indexc{cosh}§
    4582 double cosh( double );
    4583 long double cosh( long double );
    4584 float _Complex cosh( float _Complex );
    4585 double _Complex cosh( double _Complex );
    4586 long double _Complex cosh( long double _Complex );
    4587 
    4588 float tanh( float );§\indexc{tanh}§
    4589 double tanh( double );
    4590 long double tanh( long double );
    4591 float _Complex tanh( float _Complex );
    4592 double _Complex tanh( double _Complex );
    4593 long double _Complex tanh( long double _Complex );
    4594 
    4595 float asinh( float );§\indexc{asinh}§
    4596 double asinh( double );
    4597 long double asinh( long double );
    4598 float _Complex asinh( float _Complex );
    4599 double _Complex asinh( double _Complex );
    4600 long double _Complex asinh( long double _Complex );
    4601 
    4602 float acosh( float );§\indexc{acosh}§
    4603 double acosh( double );
    4604 long double acosh( long double );
    4605 float _Complex acosh( float _Complex );
    4606 double _Complex acosh( double _Complex );
    4607 long double _Complex acosh( long double _Complex );
    4608 
    4609 float atanh( float );§\indexc{atanh}§
    4610 double atanh( double );
    4611 long double atanh( long double );
    4612 float _Complex atanh( float _Complex );
    4613 double _Complex atanh( double _Complex );
    4614 long double _Complex atanh( long double _Complex );
    4615 \end{lstlisting}
    4616 
    4617 
    4618 \subsection{Error / Gamma}
    4619 
    4620 \begin{lstlisting}
    4621 float erf( float );§\indexc{erf}§
    4622 double erf( double );
    4623 long double erf( long double );
    4624 float _Complex erf( float _Complex );
    4625 double _Complex erf( double _Complex );
    4626 long double _Complex erf( long double _Complex );
    4627 
    4628 float erfc( float );§\indexc{erfc}§
    4629 double erfc( double );
    4630 long double erfc( long double );
    4631 float _Complex erfc( float _Complex );
    4632 double _Complex erfc( double _Complex );
    4633 long double _Complex erfc( long double _Complex );
    4634 
    4635 float lgamma( float );§\indexc{lgamma}§
    4636 double lgamma( double );
    4637 long double lgamma( long double );
    4638 float lgamma( float, int * );
    4639 double lgamma( double, int * );
    4640 long double lgamma( long double, int * );
    4641 
    4642 float tgamma( float );§\indexc{tgamma}§
    4643 double tgamma( double );
    4644 long double tgamma( long double );
    4645 \end{lstlisting}
    4646 
    4647 
    4648 \subsection{Nearest Integer}
    4649 
    4650 \begin{lstlisting}
    4651 float floor( float );§\indexc{floor}§
    4652 double floor( double );
    4653 long double floor( long double );
    4654 
    4655 float ceil( float );§\indexc{ceil}§
    4656 double ceil( double );
    4657 long double ceil( long double );
    4658 
    4659 float trunc( float );§\indexc{trunc}§
    4660 double trunc( double );
    4661 long double trunc( long double );
    4662 
    4663 float rint( float );§\indexc{rint}§
    4664 long double rint( long double );
    4665 long int rint( float );
    4666 long int rint( double );
    4667 long int rint( long double );
    4668 long long int rint( float );
    4669 long long int rint( double );
    4670 long long int rint( long double );
    4671 
    4672 long int lrint( float );§\indexc{lrint}§
    4673 long int lrint( double );
    4674 long int lrint( long double );
    4675 long long int llrint( float );
    4676 long long int llrint( double );
    4677 long long int llrint( long double );
    4678 
    4679 float nearbyint( float );§\indexc{nearbyint}§
    4680 double nearbyint( double );
    4681 long double nearbyint( long double );
    4682 
    4683 float round( float );§\indexc{round}§
    4684 long double round( long double );
    4685 long int round( float );
    4686 long int round( double );
    4687 long int round( long double );
    4688 long long int round( float );
    4689 long long int round( double );
    4690 long long int round( long double );
    4691 
    4692 long int lround( float );§\indexc{lround}§
    4693 long int lround( double );
    4694 long int lround( long double );
    4695 long long int llround( float );
    4696 long long int llround( double );
    4697 long long int llround( long double );
    4698 \end{lstlisting}
    4699 
    4700 
    4701 \subsection{Manipulation}
    4702 
    4703 \begin{lstlisting}
    4704 float copysign( float, float );§\indexc{copysign}§
    4705 double copysign( double, double );
    4706 long double copysign( long double, long double );
    4707 
    4708 float frexp( float, int * );§\indexc{frexp}§
    4709 double frexp( double, int * );
    4710 long double frexp( long double, int * );
    4711 
    4712 float ldexp( float, int );§\indexc{ldexp}§
    4713 double ldexp( double, int );
    4714 long double ldexp( long double, int );
    4715 
    4716 [ float, float ] modf( float );§\indexc{modf}§
    4717 float modf( float, float * );
    4718 [ double, double ] modf( double );
    4719 double modf( double, double * );
    4720 [ long double, long double ] modf( long double );
    4721 long double modf( long double, long double * );
    4722 
    4723 float nextafter( float, float );§\indexc{nextafter}§
    4724 double nextafter( double, double );
    4725 long double nextafter( long double, long double );
    4726 
    4727 float nexttoward( float, long double );§\indexc{nexttoward}§
    4728 double nexttoward( double, long double );
    4729 long double nexttoward( long double, long double );
    4730 
    4731 float scalbn( float, int );§\indexc{scalbn}§
    4732 double scalbn( double, int );
    4733 long double scalbn( long double, int );
    4734 
    4735 float scalbln( float, long int );§\indexc{scalbln}§
    4736 double scalbln( double, long int );
    4737 long double scalbln( long double, long int );
    4738 \end{lstlisting}
    4739 
    4740 
    4741 \section{Rational Numbers}
    4742 \label{s:RationalNumbers}
    4743 
    4744 Rational 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.
    4745 When 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
    4749 struct Rational {§\indexc{Rational}§
    4750         long int numerator, denominator;                                        // invariant: denominator > 0
    4751 }; // Rational
    4752 
    4753 // constants
    4754 extern struct Rational 0;
    4755 extern struct Rational 1;
    4756 
    4757 // constructors
    4758 Rational rational();
    4759 Rational rational( long int n );
    4760 Rational rational( long int n, long int d );
    4761 
    4762 // getter/setter for numerator/denominator
    4763 long int numerator( Rational r );
    4764 long int numerator( Rational r, long int n );
    4765 long int denominator( Rational r );
    4766 long int denominator( Rational r, long int d );
    4767 
    4768 // comparison
    4769 int ?==?( Rational l, Rational r );
    4770 int ?!=?( Rational l, Rational r );
    4771 int ?<?( Rational l, Rational r );
    4772 int ?<=?( Rational l, Rational r );
    4773 int ?>?( Rational l, Rational r );
    4774 int ?>=?( Rational l, Rational r );
    4775 
    4776 // arithmetic
    4777 Rational -?( Rational r );
    4778 Rational ?+?( Rational l, Rational r );
    4779 Rational ?-?( Rational l, Rational r );
    4780 Rational ?*?( Rational l, Rational r );
    4781 Rational ?/?( Rational l, Rational r );
    4782 
    4783 // conversion
    4784 double widen( Rational r );
    4785 Rational narrow( double f, long int md );
    4786 
    4787 // I/O
    4788 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
    4789 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
    4790 \end{lstlisting}
    4791 
    4792 
    47934257\bibliographystyle{plain}
    4794 \bibliography{cfa}
     4258\bibliography{/usr/local/bibliographies/pl.bib}
    47954259
    47964260
Note: See TracChangeset for help on using the changeset viewer.