Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r45576af9 re229c22  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Jun 10 16:38:22 2016
    14 %% Update Count     : 394
     13%% Last Modified On : Fri Jun  3 09:49:31 2016
     14%% Update Count     : 281
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    1818
    1919% inline code ©...© (copyright symbol) emacs: C-q M-)
    20 % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
    21 % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
    22 % green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
    23 % Latex escape §...§ (section symbol) emacs: C-q M-'
     20% red highlighting ®...® (registered trademark sumbol) emacs: C-q M-.
     21% latex escape §...§ (section symbol) emacs: C-q M-'
    2422% keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
    2523% math escape $...$ (dollar symbol)
    2624
    27 \documentclass[twoside,11pt]{article}
     25\documentclass[openright,twoside]{article}
    2826%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2927
     
    3432\usepackage{fullpage,times,comment}
    3533\usepackage{epic,eepic}
    36 \usepackage{upquote}                                                                    % switch curled `'" to straight `'"
     34\usepackage{upquote}                                                                    % switch curled `' to straight `'
    3735\usepackage{xspace}
    3836\usepackage{varioref}                                                                   % extended references
    3937\usepackage{listings}                                                                   % format program code
    40 \usepackage[flushmargin]{footmisc}                                              % support label/reference in footnote
     38\usepackage{footmisc}                                                                   % support label/reference in footnote
    4139\usepackage{latexsym}                                   % \Box glyph
    4240\usepackage{mathptmx}                                   % better math font with "times"
    43 \usepackage[usenames]{color}
    4441\usepackage[pagewise]{lineno}
    4542\renewcommand{\linenumberfont}{\scriptsize\sffamily}
    46 \input{common}                                          % bespoke macros used in the document
    4743\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
    4844\usepackage{breakurl}
    4945\renewcommand{\UrlFont}{\small\sf}
    5046
     47%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     48
     49% Bespoke macros used in the document.
     50\input{common}
     51
     52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     53
    5154% Names used in the document.
    5255
    5356\newcommand{\Version}{1.0.0}
    5457\newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace}
    55 
    56 \newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}}
    57 \newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
    58 \newcommand{\R}[1]{\Textbf{#1}}
    59 \newcommand{\B}[1]{{\Textbf[blue]{#1}}}
    60 \newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}}
    6158
    6259%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    113110
    114111\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.
    115 The syntax of the \CFA language builds from C, and should look immediately familiar to C/\CC programmers.
     112The syntax of the \CFA language builds from C, and should look immediately familiar to C programmers.
    116113% Any language feature that is not described here can be assumed to be using the standard C11 syntax.
    117 \CFA adds many modern programming-language features that directly lead to increased \emph{safety} and \emph{productivity}, while maintaining interoperability with existing C programs and achieving C performance.
     114\CFA adds many modern programming-language features that directly leads to increased \emph{safety} and \emph{productivity}, while maintaining interoperability with existing C programs and achieving C performance.
    118115Like C, \CFA is a statically typed, procedural language with a low-overhead runtime, meaning there is no global garbage-collection.
    119116The primary new features include parametric-polymorphism routines and types, exceptions, concurrency, and modules.
     
    126123New programs can be written in \CFA using a combination of C and \CFA features.
    127124\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.
    128 \CFA has 30 years of hindsight and a clean starting point.
     125\CFA has 30 years of hindsight and clean starting point.
    129126
    130127Like \CC, there may be both an old and new ways to achieve the same effect.
    131128For example, the following programs compare the \CFA and C I/O mechanisms.
    132129\begin{quote2}
    133 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    134 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     130\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     131\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    135132\begin{lstlisting}
    136133#include <fstream>
    137134int main( void ) {
    138135        int x = 0, y = 1, z = 2;
    139         ®sout | x | y | z | endl;®
     136        sout | x | y | z | endl;
    140137}
    141138\end{lstlisting}
     
    145142int main( void ) {
    146143        int x = 0, y = 1, z = 2;
    147         ®printf( "%d %d %d\n", x, y, z );®
     144        printf( "%d %d %d\n", x, y, z );
    148145}
    149146\end{lstlisting}
     
    151148\end{quote2}
    152149Both programs output the same result.
    153 While the \CFA I/O looks similar to the \CC output style, there are important differences, such as automatic spacing between variables as in Python (see also~\VRef{s:IOLibrary}).
    154 
    155 This document is a user manual for the \CFA programming language, targeted at \CFA programmers.
     150While 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}).
     151
     152This document is a reference manual for the \CFA programming language, targeted at \CFA programmers.
    156153Implementers may refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
    157154In its current state, this document covers the intended core features of the language.
     
    162159\section{History}
    163160
    164 The \CFA project started with K-W C~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and extended assignment capabilities using the notion of tuples.
     161The \CFA project started with K-W C~\cite{Till89,Buhr94a}, which extended C with new declaration syntax, multiple return values from routines, and extended assignment capabilities using the notion of tuples.
    165162(See~\cite{Werther96} for some similar work, but for \CC.)
    166163The 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.
    167164A 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.
    168 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.
     165As 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.
    169166
    170167
     
    172169
    173170Even 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.
    174 For system programming, where direct access to hardware and dealing with real-time issues is a requirement, C is usually the language of choice.
     171For systems programming, where direct access to hardware and dealing with real-time issues is a requirement, C is usually the language of choice.
    175172As well, there are millions of lines of C legacy code, forming the base for many software development projects (especially on UNIX systems).
    176173The TIOBE index (\url{http://www.tiobe.com/tiobe_index}) for March 2016 shows programming-language popularity, with Java 20.5\%, C 14.5\%, \CC 6.7\%, \CS 4.3\%, Python 4.3\%, and all other programming languages below 3\%.
    177 As well, for 30 years, C has been the number 1 and 2 most popular programming language:
    178 \begin{center}
    179 \setlength{\tabcolsep}{1.5ex}
    180 \begin{tabular}{@{}r|c|c|c|c|c|c|c@{}}
    181 Ranking & 2016  & 2011  & 2006  & 2001  & 1996  & 1991  & 1986          \\
    182 \hline
    183 Java    & 1             & 1             & 1             & 3             & 29    & -             & -                     \\
    184 \hline
    185 \R{C}   & \R{2} & \R{2} & \R{2} & \R{1} & \R{1} & \R{1} & \R{1}         \\
    186 \hline
    187 \CC             & 3             & 3             & 3             & 2             & 2             & 2             & 7                     \\
    188 \end{tabular}
    189 \end{center}
    190174Hence, C is still an extremely important programming language, with double the usage of \CC, where \CC itself is largely C code.
    191175Finally, love it or hate it, C has been an important and influential part of computer science for 40 years and it appears it will continue to be for many more years.
     
    194178The goal of this project is to engineer modern language features into C in an evolutionary rather than revolutionary way.
    195179\CC~\cite{c++,ANSI14:C++} is an example of a similar project;
    196 however, it largely extended the language, and did not address many existing problems.\footnote{%
     180however, it largely extended the language, and did not address existing problems.\footnote{%
    197181Two important existing problems addressed were changing the type of character literals from ©int© to ©char© and enumerator from ©int© to the type of its enumerators.}
    198 Fortran~\cite{Fortran08}, Ada~\cite{Ada12}, and Cobol~\cite{Cobol14} are examples of programming languages that took an evolutionary approach, where modern language features (e.g., objects, concurrency) are added and problems fixed within the framework of the existing language.
     182Fortran~\cite{Fortran08}, Ada~\cite{Ada12}, and Cobol~\cite{Cobol14} are examples of programming languages that took an evolutionary approach, where modern language features are added and problems fixed within the framework of the existing language.
    199183Java~\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.
    200184These languages have different syntax and semantics from C, and do not interoperate directly with C, largely because of garbage collection.
    201185As a result, there is a significant learning curve to move to these languages, and C legacy-code must be rewritten.
    202 These costs can be prohibitive for many companies with a large software base in C/\CC, and a significant number of programmers requiring retraining to a new programming language.
    203 
    204 The result of this project is a language that is largely backwards compatible with C11~\cite{C11}, but fixing some of the well known C problems and containing many modern language features.
    205 Without significant extension to the C programming language, it is becoming unable to cope with the needs of modern programming problems and programmers;
     186These 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.
     187
     188The result of this project is a language that is largely backwards compatible with C11~\cite{C11}, but containing many modern language features and fixing some of the well known C problems.
     189Without significant extension to the C programming language, C will be unable to cope with the needs of modern programming problems and programmers;
    206190as a result, it will fade into disuse.
    207191Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern programming language.
     
    216200This feature allows users of \CFA to take advantage of the existing panoply of C libraries from inside their \CFA code.
    217201In 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.
    218 Language developers often state that adequate library support takes more work than designing and implementing the language itself.
     202Programming-language developers often state that adequate library support takes more work than designing and implementing the language itself.
    219203Like \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.
    220 Hence, \CFA begins by leveraging the large repository of C libraries with little cost.
    221204
    222205However, it is necessary to differentiate between C and \CFA code because of name overloading, as for \CC.
    223 For example, the C math-library provides the following routines for computing the absolute value of the basic types: ©abs©, ©labs©, ©llabs©, ©fabs©, ©fabsf©, ©fabsl©, ©cabsf©, ©cabs©, and ©cabsl©.
    224 Whereas, \CFA wraps each of these routines into ones with the common name ©abs©:
     206For example, the C math-library provides the following routines for computing the absolute value of the basic type: ©abs©, ©labs©, ©llabs©, ©fabs©, ©fabsf©, ©fabsl©, ©cabsf©, ©cabs©, and ©cabsl©.
     207Whereas, \CFA wraps each of these routines into one with the common name ©abs©.
    225208\begin{lstlisting}
    226209char abs( char );
    227210extern "C" {
    228 int abs( int );                                 // use default C routine for int
     211int abs( int );                         // use default C routine for int
    229212} // extern "C"
    230213long int abs( long int );
     
    250233\section[Compiling CFA Program]{Compiling \CFA Program}
    251234
    252 The command ©cfa© is used to compile \CFA program(s), and is based on the GNU ©gcc©\index{gcc} command, e.g.:
     235The command ©cfa© is used to compile \CFA program(s).
     236This command works like the GNU ©gcc©\index{gcc} command, e.g.:
    253237\begin{lstlisting}
    254238cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] C/§\CFA§-files [ assembler/loader-files ]
     
    256240By default, \CFA programs having the following ©gcc© flags turned on:
    257241\begin{description}
    258 \item\hspace*{-0.6ex}\Indexc{-std=gnu99}\index{compilation option!-std=gnu99@{©-std=gnu99©}}
     242\item\hspace*{-4pt}\Indexc{-std=gnu99}\index{compilation option!-std=gnu99@{©-std=gnu99©}}
    259243The 1999 C standard plus GNU extensions.
    260 \item\hspace*{-0.6ex}\Indexc{-fgnu89-¶inline¶}\index{compilation option!-fgnu89-inline@{©-fgnu89-¶inline¶©}}
     244\item\hspace*{-4pt}\Indexc{-fgnu89-¶inline¶}\index{compilation option!-fgnu89-inline@{©-fgnu89-¶inline¶©}}
    261245Use the traditional GNU semantics for inline routines in C99 mode, which allows inline routines in header files.
    262246\end{description}
    263247The following new \CFA option is available:
    264248\begin{description}
    265 \item\hspace*{-0.6ex}\Indexc{-CFA}\index{compilation option!-CFA@{©-CFA©}}
     249\item\hspace*{-4pt}\Indexc{-CFA}\index{compilation option!-CFA@{©-CFA©}}
    266250Only 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.
    267251\end{description}
     
    269253The following preprocessor variables are available:
    270254\begin{description}
    271 \item\hspace*{-0.6ex}\Indexc{__CFA__}\index{preprocessor variables!__CFA__@{©__CFA__©}}
     255\item\hspace*{-4pt}\Indexc{__CFA__}\index{preprocessor variables!__CFA__@{©__CFA__©}}
    272256is always available during preprocessing and its value is the current major \Index{version number} of \CFA.\footnote{
    273257The C preprocessor allows only integer values in a preprocessor variable so a value like ``\Version'' is not allowed.
    274258Hence, the need to have three variables for the major, minor and patch version number.}
    275259
    276 \item\hspace*{-0.6ex}\Indexc{__CFA_MINOR__}\index{preprocessor variables!__CFA_MINOR__@{©__CFA_MINOR__©}}
     260\item\hspace*{-4pt}\Indexc{__CFA_MINOR__}\index{preprocessor variables!__CFA_MINOR__@{©__CFA_MINOR__©}}
    277261is always available during preprocessing and its value is the current minor \Index{version number} of \CFA.
    278262
    279 \item\hspace*{-0.6ex}\Indexc{__CFA_PATCH__}\index{preprocessor variables!__CFA_PATCH__@©__CFA_PATCH__©}
     263\item\hspace*{-4pt}\Indexc{__CFA_PATCH__}\index{preprocessor variables!__CFA_PATCH__@©__CFA_PATCH__©}
    280264is always available during preprocessing and its value is the current patch \Index{version number} of \CFA.
    281265
    282 \item\hspace*{-0.6ex}\Indexc{__CFA__}\index{preprocessor variables!__CFA__@©__CFA__©} and \Indexc{__CFORALL__}\index{preprocessor variables!__CFORALL__@©__CFORALL__©}
    283 are always available during preprocessing and have no value.
     266\item\hspace*{-4pt}\Indexc{__CFORALL__}\index{preprocessor variables!__CFORALL__@©__CFORALL__©}
     267is always available during preprocessing and it has no value.
    284268\end{description}
    285269
     
    288272\begin{lstlisting}
    289273#ifndef __CFORALL__
    290 #include <stdio.h>                              // C header file
     274#include <stdio.h>                      // C header file
    291275#else
    292 #include <fstream>                              // §\CFA{}§ header file
     276#include <fstream>                      // §\CFA{}§ header file
    293277#endif
    294278\end{lstlisting}
     
    300284Numeric constants are extended to allow \Index{underscore}s within constants\index{constant!underscore}, e.g.:
    301285\begin{lstlisting}
    302 2®_®147®_®483®_®648;                                    // decimal constant
    303 56_ul;                                                  // decimal unsigned long constant
    304 0_377;                                                  // octal constant
    305 0x_ff_ff;                                               // hexadecimal constant
    306 0x_ef3d_aa5c;                                   // hexadecimal constant
    307 3.141_592_654;                                  // floating point constant
    308 10_e_+1_00;                                             // floating point constant
    309 0x_ff_ff_p_3;                                   // hexadecimal floating point
    310 0x_1.ffff_ffff_p_128_l;                 // hexadecimal floating point long constant
    311 L_"\x_ff_ee";                                   // wide character constant
     2862®_®147®_®483®_®648;                            // decimal constant
     28756_ul;                                          // decimal unsigned long constant
     2880_377;                                          // octal constant
     2890x_ff_ff;                                       // hexadecimal constant
     2900x_ef3d_aa5c;                           // hexadecimal constant
     2913.141_592_654;                          // floating point constant
     29210_e_+1_00;                                     // floating point constant
     2930x_ff_ff_p_3;                           // hexadecimal floating point
     2940x_1.ffff_ffff_p_128_l;         // hexadecimal floating point long constant
     295L_"\x_ff_ee";                           // wide character constant
    312296\end{lstlisting}
    313297The rules for placement of underscores is as follows:
     
    327311\end{enumerate}
    328312It 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).
    329 This extension is backwards compatible, matches with the use of underscore in variable names, and appears in Ada and Java 8.
     313This extension is backwards compatible, matches with the use of underscore in variable names, and appears in Ada and Java.
    330314
    331315
     
    337321\begin{quote2}
    338322\begin{tabular}{@{}ll@{}}
    339 \begin{lstlisting}
    340 int *x[5]
     323\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
     324int *x[ 5 ]
    341325\end{lstlisting}
    342326&
     
    348332For example, a routine returning a pointer to an array of integers is defined and used in the following way:
    349333\begin{lstlisting}
    350 int (*f())[5] {...};                    // definition mimics usage
    351 ... (*f())[3] += 1;
     334int (*f())[ 5 ] {...};  // definition mimics usage
     335... (*f())[ 3 ] += 1;
    352336\end{lstlisting}
    353337Essentially, the return type is wrapped around the routine name in successive layers (like an onion).
    354338While attempting to make the two contexts consistent was a laudable goal, it has not worked out in practice.
    355339
    356 \CFA provides its own type, variable and routine declarations, using a different syntax.
    357 The new declarations place qualifiers to the left of the base type, while C declarations place qualifiers to the right of the base type.
    358 In the following example, \R{red} is for the base type and \B{blue} is for the qualifiers.
    359 The \CFA declarations move the qualifiers to the left of the base type, i.e., blue to the left of the red, while the qualifiers have the same meaning but are ordered left to left to right to specify the variable's type.
    360 \begin{quote2}
    361 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    362 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    363 \begin{lstlisting}
    364 ß[5] *ß ®int® x1;
    365 ß* [5]ß ®int® x2;
    366 ß[* [5] int]ß f®( int p )®;
    367 \end{lstlisting}
    368 &
    369 \begin{lstlisting}
    370 ®int® ß*ß x1 ß[5]ß;
    371 ®int® ß(*ßx2ß)[5]ß;
    372 ßint (*ßf®( int p )®ß)[5]ß;
    373 \end{lstlisting}
    374 \end{tabular}
    375 \end{quote2}
     340\CFA provides its own type, variable and routine declarations, using a slightly different syntax.
     341The new declarations place modifiers to the left of the base type, while C declarations place modifiers to the right of the base type.
    376342The only exception is bit field specification, which always appear to the right of the base type.
    377 % Specifically, the character ©*© is used to indicate a pointer, square brackets ©[©\,©]© are used to represent an array or function return value, and parentheses ©()© are used to indicate a routine parameter.
    378 However, unlike C, \CFA type declaration tokens are distributed across all variables in the declaration list.
     343C and the new \CFA declarations may appear together in the same program block, but cannot be mixed within a specific declaration.
     344
     345In \CFA declarations, the same tokens are used as in C: the character ©*© is used to indicate a pointer, square brackets ©[©\,©]© are used to represent an array, and parentheses ©()© are used to indicate a routine parameter.
     346However, unlike C, \CFA type declaration tokens are specified from left to right and the entire type specification is distributed across all variables in the declaration list.
    379347For instance, variables ©x© and ©y© of type pointer to integer are defined in \CFA as follows:
    380348\begin{quote2}
    381 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    382 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    383 \begin{lstlisting}
    384 ®*® int x, y;
     349\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     350\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
     351\begin{lstlisting}
     352®* int x, y;®
    385353\end{lstlisting}
    386354&
    387355\begin{lstlisting}
    388 int ®*®x, ®*®y;
     356int *x, *y;
    389357\end{lstlisting}
    390358\end{tabular}
     
    392360Other examples are:
    393361\begin{quote2}
    394 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    395 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     362\begin{tabular}{@{}l@{\hspace{30pt}}l@{\hspace{20pt}}l@{}}
     363\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    396364\begin{lstlisting}
    397365[ 5 ] int z;
     
    429397\end{quote2}
    430398
    431 All type qualifiers, e.g., ©const©, ©volatile©, etc., are used in the normal way with the new declarations and also appear left to right, e.g.:
     399All type qualifiers, i.e., ©const© and ©volatile©, are used in the normal way with the new declarations but appear left to right, e.g.:
    432400\begin{quote2}
    433 \begin{tabular}{@{}l@{\hspace{1em}}l@{\hspace{1em}}l@{}}
    434 \multicolumn{1}{c@{\hspace{1em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{1em}}}{\textbf{C}} \\
     401\begin{tabular}{@{}l@{\hspace{30pt}}l@{\hspace{20pt}}l@{}}
     402\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    435403\begin{lstlisting}
    436404const * const int x;
     
    449417\end{tabular}
    450418\end{quote2}
    451 All declaration qualifiers, e.g., ©extern©, ©static©, etc., are used in the normal way with the new declarations but can only appear at the start of a \CFA routine declaration,\footnote{\label{StorageClassSpecifier}
     419All declaration qualifiers, i.e., ©extern©, ©static©, etc., are used in the normal way with the new declarations but can only appear at the start of a \CFA routine declaration,\footnote{\label{StorageClassSpecifier}
    452420The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.~\cite[\S~6.11.5(1)]{C11}} e.g.:
    453421\begin{quote2}
    454 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    455 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     422\begin{tabular}{@{}l@{\hspace{30pt}}l@{\hspace{20pt}}l@{}}
     423\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    456424\begin{lstlisting}
    457425extern [ 5 ] int x;
     
    475443e.g.:
    476444\begin{lstlisting}
    477 x;                                                              // int x
    478 *y;                                                             // int *y
    479 f( p1, p2 );                                    // int f( int p1, int p2 );
    480 f( p1, p2 ) {}                                  // int f( int p1, int p2 ) {}
    481 \end{lstlisting}
    482 
    483 Finally, new \CFA declarations may appear together with C declarations in the same program block, but cannot be mixed within a specific declaration.
     445x;                                              // int x
     446*y;                                             // int *y
     447f( p1, p2 );                    // int f( int p1, int p2 );
     448f( p1, p2 ) {}                  // int f( int p1, int p2 ) {}
     449\end{lstlisting}
     450
     451As stated above, the two styles of declaration may appear together in the same block.
    484452Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.
    485453Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX systems.
     
    490458The new declaration syntax can be used in other contexts where types are required, e.g., casts and the pseudo-routine ©sizeof©:
    491459\begin{quote2}
    492 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    493 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    494 \begin{lstlisting}
    495 y = (®* int®)x;
    496 i = sizeof(®[ 5 ] * int®);
     460\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     461\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
     462\begin{lstlisting}
     463y = (* int)x;
     464i = sizeof([ 5 ] * int);
    497465\end{lstlisting}
    498466&
    499467\begin{lstlisting}
    500 y = (®int *®)x;
    501 i = sizeof(®int *[ 5 ]®);
     468y = (int *)x;
     469i = sizeof(int *[ 5 ]);
    502470\end{lstlisting}
    503471\end{tabular}
     
    508476
    509477\CFA also supports a new syntax for routine definition, as well as ISO C and K\&R routine syntax.
    510 The point of the new syntax is to allow returning multiple values from a routine~\cite{Galletly96,CLU}, e.g.:
     478The point of the new syntax is to allow returning multiple values from a routine~\cite{CLU,Galletly96}, e.g.:
    511479\begin{lstlisting}
    512480®[ int o1, int o2, char o3 ]® f( int i1, char i2, char i3 ) {
     
    522490Declaration qualifiers can only appear at the start of a routine definition, e.g.:
    523491\begin{lstlisting}
    524 ®extern® [ int x ] g( int y ) {§\,§}
     492extern [ int x ] g( int y ) {§\,§}
    525493\end{lstlisting}
    526494Lastly, if there are no output parameters or input parameters, the brackets and/or parentheses must still be specified;
    527495in 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:
    528496\begin{lstlisting}
    529 [§\,§] g();                                                     // no input or output parameters
    530 [ void ] g( void );                             // no input or output parameters
     497[§\,§] g();                                             // no input or output parameters
     498[ void ] g( void );                     // no input or output parameters
    531499\end{lstlisting}
    532500
     
    535503[ i, j, ch ] = f( 3, 'a', ch );
    536504\end{lstlisting}
    537 The list of return values from f and the grouping on the left-hand side of the assignment is called a \newterm{return list} and discussed in Section 12.
     505The list of return values from f and the grouping on the left-hand side of the assignment is called a tuple and discussed in Section 12.
    538506
    539507\CFA style declarations cannot be used to declare parameters for K\&R style routine definitions because of the following ambiguity:
     
    546514\begin{lstlisting}
    547515typedef int foo;
    548 int f( int (* foo) );                   // foo is redefined as a parameter name
     516int f( int (* foo) );           // foo is redefined as a parameter name
    549517\end{lstlisting}
    550518The string ``©int (* foo)©'' declares a C-style named-parameter of type pointer to an integer (the parenthesis are superfluous), while the same string declares a \CFA style unnamed parameter of type routine returning integer with unnamed parameter of type pointer to foo.
    551 The redefinition of a type name in a parameter list is the only context in C where the character ©*© can appear to the left of a type name, and \CFA relies on all type qualifier characters appearing to the right of the type name.
     519The redefinition of a type name in a parameter list is the only context in C where the character ©*© can appear to the left of a type name, and \CFA relies on all type modifier characters appearing to the right of the type name.
    552520The inability to use \CFA declarations in these two contexts is probably a blessing because it precludes programmers from arbitrarily switching between declarations forms within a declaration contexts.
    553521
    554522C-style declarations can be used to declare parameters for \CFA style routine definitions, e.g.:
    555523\begin{lstlisting}
    556 [ int ] f( * int, int * );              // returns an integer, accepts 2 pointers to integers
    557 [ * int, int * ] f( int );              // returns 2 pointers to integers, accepts an integer
     524[ int ] f( * int, int * );      // returns an integer, accepts 2 pointers to integers
     525[ * int, int * ] f( int );      // returns 2 pointers to integers, accepts an integer
    558526\end{lstlisting}
    559527The reason for allowing both declaration styles in the new context is for backwards compatibility with existing preprocessor macros that generate C-style declaration-syntax, as in:
    560528\begin{lstlisting}
    561529#define ptoa( n, d ) int (*n)[ d ]
    562 int f( ptoa( p, 5 ) ) ...               // expands to int f( int (*p)[ 5 ] )
    563 [ int ] f( ptoa( p, 5 ) ) ...   // expands to [ int ] f( int (*p)[ 5 ] )
     530int f( ptoa(p,5) ) ...          // expands to int f( int (*p)[ 5 ] )
     531[ int ] f( ptoa(p,5) ) ...      // expands to [ int ] f( int (*p)[ 5 ] )
    564532\end{lstlisting}
    565533Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
    566534
    567535
    568 \subsection{Named Return Values}
    569 
    570 \Index{Named return values} handle the case where it is necessary to define a local variable whose value is then returned in a ©return© statement, as in:
     536\subsection{Returning Values}
     537
     538Named return values handle the case where it is necessary to define a local variable whose value is then returned in a ©return© statement, as in:
    571539\begin{lstlisting}
    572540int f() {
     
    577545\end{lstlisting}
    578546Because the value in the return variable is automatically returned when a \CFA routine terminates, the ©return© statement \emph{does not} contain an expression, as in:
    579 \newline
    580 \begin{minipage}{\linewidth}
    581 \begin{lstlisting}
    582 ®[ int x, int y ]® f() {
    583         int z;
    584         ... x = 0; ... y = z; ...
    585         ®return;® // implicitly return x, y
    586 }
    587 \end{lstlisting}
    588 \end{minipage}
    589 \newline
    590 When the return is encountered, the current values of ©x© and ©y© are returned to the calling routine.
     547\begin{lstlisting}
     548®[ int x ]® f() {
     549        ... x = 0; ... x = y; ...
     550        ®return;® // implicitly return x
     551}
     552\end{lstlisting}
     553When the return is encountered, the current value of ©x© is returned to the calling routine.
    591554As well, ``falling off the end'' of a routine without a ©return© statement is permitted, as in:
    592555\begin{lstlisting}
    593 [ int x, int y ] f() {
    594         ...
    595 } // implicitly return x, y
    596 \end{lstlisting}
    597 In this case, the current values of ©x© and ©y© are returned to the calling routine just as if a ©return© had been encountered.
     556[ int x ] f() {
     557        ... x = 0; ... x = y; ...
     558} // implicitly return x
     559\end{lstlisting}
     560In this case, the current value of ©x© is returned to the calling routine just as if a ©return© had been encountered.
    598561
    599562
     
    603566as well, parameter names are optional, e.g.:
    604567\begin{lstlisting}
    605 [ int x ] f ();                                 // returning int with no parameters
    606 [ * int ] g (int y);                    // returning pointer to int with int parameter
    607 [ ] h (int,char);                               // returning no result with int and char parameters
    608 [ * int,int ] j (int);                  // returning pointer to int and int, with int parameter
     568[ int x ] f ();                         // returning int with no parameters
     569[ * int ] g (int y);            // returning pointer to int with int parameter
     570[ ] h (int,char);                       // returning no result with int and char parameters
     571[ * int,int ] j (int);          // returning pointer to int and int, with int parameter
    609572\end{lstlisting}
    610573This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
    611574It is possible to declare multiple routine-prototypes in a single declaration, but the entire type specification is distributed across \emph{all} routine names in the declaration list (see~\VRef{s:Declarations}), e.g.:
    612575\begin{quote2}
    613 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    614 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     576\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     577\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    615578\begin{lstlisting}
    616579[ int ] f(int), g;
     
    641604for example, the following is incorrect:
    642605\begin{lstlisting}
    643 * [ int x ] f () fp;                    // routine name "f" is not allowed
     606* [ int x ] f () fp;            // routine name "f" is not allowed
    644607\end{lstlisting}
    645608
     
    774737While in theory default arguments can be simulated with overloading, as in:
    775738\begin{quote2}
    776 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    777 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{default arguments}}   & \multicolumn{1}{c}{\textbf{overloading}}      \\
     739\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     740\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{default arguments}}  & \multicolumn{1}{c}{\textbf{overloading}}      \\
    778741\begin{lstlisting}
    779742void p( int x, int y = 2, int z = 3 ) {...}
     
    810773\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.
    811774\begin{quote2}
    812 \begin{tabular}{@{}l@{\hspace{3em}}l|l@{}}
    813 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}}      & \multicolumn{1}{c}{\textbf{C Implicit Hoisting}}      & \multicolumn{1}{|c}{\textbf{\CFA}}    \\
     775\begin{tabular}{@{}l@{\hspace{30pt}}l|l@{}}
     776\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{C Type Nesting}}     & \multicolumn{1}{c}{\textbf{C Implicit Hoisting}}      & \multicolumn{1}{|c}{\textbf{\CFA}}    \\
    814777\hline
    815778\begin{lstlisting}
     
    917880
    918881
    919 \section{Lexical List}
     882\section{Tuples}
    920883
    921884In C and \CFA, lists of elements appear in several contexts, such as the parameter list for a routine call.
    922885(More contexts are added shortly.)
    923 A list of such elements is called a \newterm{lexical list}.
    924 The general syntax of a lexical list is:
     886A list of such elements is called a tuple.
     887The general syntax of a tuple is:
    925888\begin{lstlisting}
    926889[ §\emph{exprlist}§ ]
    927890\end{lstlisting}
    928891where ©$\emph{exprlist}$© is a list of one or more expressions separated by commas.
    929 The brackets, ©[]©, allow differentiating between lexical lists and expressions containing the C comma operator.
    930 The following are examples of lexical lists:
     892The brackets, ©[]©, allow differentiating between tuples and expressions containing the C comma operator.
     893The following are examples of tuples:
    931894\begin{lstlisting}
    932895[ x, y, z ]
     
    12171180\begin{figure}
    12181181\centering
    1219 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    1220 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     1182\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     1183\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    12211184\begin{lstlisting}
    12221185®L1:® for ( ... ) {
     
    12481211\vspace*{0.25in}
    12491212
    1250 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    1251 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     1213\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     1214\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    12521215\begin{lstlisting}
    12531216®L1®: for ( ... ) {
     
    14901453Therefore, the ©case© clause is extended with a list of values, as in:
    14911454\begin{quote2}
    1492 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    1493 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     1455\begin{tabular}{@{}l@{\hspace{30pt}}l@{\hspace{20pt}}l@{}}
     1456\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    14941457\begin{lstlisting}
    14951458switch ( i ) {
     
    15221485In addition, two forms of subranges are allowed to specify case values: the GNU C form and a new \CFA form.
    15231486\begin{quote2}
    1524 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    1525 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{GNU C}}     \\
     1487\begin{tabular}{@{}l@{\hspace{30pt}}l@{\hspace{20pt}}l@{}}
     1488\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{GNU C}}    \\
    15261489\begin{lstlisting}
    15271490switch ( i ) {
     
    20442007Auto type-inferencing occurs in a declaration where a variable's type is inferred from its initialization expression type.
    20452008\begin{quote2}
    2046 \begin{tabular}{@{}l@{\hspace{3em}}ll@{}}
    2047 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CC}} & \multicolumn{1}{c}{©gcc©}\index{gcc} \\
     2009\begin{tabular}{@{}l@{\hspace{30pt}}ll@{}}
     2010\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CC}}        & \multicolumn{1}{c}{©gcc©}\index{gcc} \\
    20482011\begin{lstlisting}
    20492012
     
    41474110The general case is printing out a sequence of variables separated by whitespace.
    41484111\begin{quote2}
    4149 \begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    4150 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
     4112\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     4113\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{\CC}}      \\
    41514114\begin{lstlisting}
    41524115int x = 0, y = 1, z = 2;
Note: See TracChangeset for help on using the changeset viewer.