Changeset 418d773a


Ignore:
Timestamp:
Feb 13, 2018, 11:37:00 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
9c75137
Parents:
c4d4ecf
Message:

rename LaTeX macroquote2 to cquote, and update user manual

Location:
doc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.tex

    rc4d4ecf r418d773a  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Feb  4 10:38:26 2018
    14 %% Update Count     : 365
     13%% Last Modified On : Tue Feb 13 08:19:07 2018
     14%% Update Count     : 367
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    177177\makeatother
    178178
    179 \newenvironment{quote2}{%
    180         \list{}{\lstset{resetmargins=true,aboveskip=0pt,belowskip=0pt}\topsep=4pt\parsep=0pt\leftmargin=\parindent\rightmargin\leftmargin}%
     179\newenvironment{cquote}{%
     180        \list{}{\lstset{resetmargins=true,aboveskip=0pt,belowskip=0pt}\topsep=4pt\parsep=0pt\leftmargin=\parindentlnth\rightmargin\leftmargin}%
    181181        \item\relax
    182182}{%
    183183        \endlist
    184 }% quote2
     184}% cquote
    185185
    186186\newenvironment{rationale}{%
    187   \begin{quote2}\noindent$\Box$\enspace
     187  \begin{cquote}\noindent$\Box$\enspace
    188188}{%
    189   \hfill\enspace$\Box$\end{quote2}
     189  \hfill\enspace$\Box$\end{cquote}
    190190}%
    191191
     
    201201\newenvironment{syntax}{
    202202\paragraph{Syntax}
    203 \begin{quote2}
     203\begin{cquote}
    204204\begin{description}[noitemsep,leftmargin=\parindentlnth]
    205205}{
    206206\end{description}
    207 \end{quote2}
     207\end{cquote}
    208208}
    209209% \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]}
  • doc/user/user.tex

    rc4d4ecf r418d773a  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Wed Jan 31 22:29:25 2018
    14 %% Update Count     : 3147
     13%% Last Modified On : Tue Feb 13 08:31:21 2018
     14%% Update Count     : 3161
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    161161Like \Index*[C++]{\CC{}}, there may be both an old and new ways to achieve the same effect.
    162162For example, the following programs compare the \CFA, C, and \CC I/O mechanisms, where the programs output the same result.
    163 \begin{quote2}
     163\begin{cquote}
    164164\begin{tabular}{@{}l@{\hspace{1.5em}}l@{\hspace{1.5em}}l@{}}
    165165\multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{C}} & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{\CC}}      \\
     
    191191\end{cfa}
    192192\end{tabular}
    193 \end{quote2}
     193\end{cquote}
    194194While the \CFA I/O looks similar to the \Index*[C++]{\CC{}} output style, there are important differences, such as automatic spacing between variables as in \Index*{Python} (see~\VRef{s:IOLibrary}).
    195195
     
    274274
    275275\begin{comment}
    276 A simple example is leveraging the existing type-unsafe (©void *©) C ©bsearch© to binary search a sorted floating-point array:
     276A simple example is leveraging the existing type-unsafe (©void *©) C ©bsearch© to binary search a sorted floating array:
    277277\begin{lstlisting}
    278278void * bsearch( const void * key, const void * base, size_t dim, size_t size,
     
    282282                                *(double *)t2 < *(double *)t1 ? 1 : 0; }
    283283
    284 double key = 5.0, vals[10] = { /* 10 sorted floating-point values */ };
     284double key = 5.0, vals[10] = { /* 10 sorted floating values */ };
    285285double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp );      $\C{// search sorted array}$
    286286\end{lstlisting}
     
    4444440x®_®ff®_®ff;                                                   §\C{// hexadecimal constant}§
    4454450x®_®ef3d®_®aa5c;                                               §\C{// hexadecimal constant}§
    446 3.141®_®592®_®654;                                              §\C{// floating point constant}§
    447 10®_®e®_®+1®_®00;                                               §\C{// floating point constant}§
    448 0x®_®ff®_®ff®_®p®_®3;                                   §\C{// hexadecimal floating point
    449 0x®_®1.ffff®_®ffff®_®p®_®128®_®l;               §\C{// hexadecimal floating point long constant}§
     4463.141®_®592®_®654;                                              §\C{// floating constant}§
     44710®_®e®_®+1®_®00;                                               §\C{// floating constant}§
     4480x®_®ff®_®ff®_®p®_®3;                                   §\C{// hexadecimal floating
     4490x®_®1.ffff®_®ffff®_®p®_®128®_®l;               §\C{// hexadecimal floating long constant}§
    450450L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§;     §\C{// wide character constant}§
    451451\end{cfa}
     
    501501\label{f:HeaderFileInterposition}
    502502\end{figure}
     503
     504
     505\section{Exponentiation Operator}
     506
     507C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation.
     508\CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@\lstinline$?\?$} and ©?\=?©\index{?\\=?@\lstinline$?\=?$}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
     509The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©.
     510
     511As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
     512Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication\footnote{The multiplication computation is $O(\log y)$.} (or shifting if the base is 2).
     513Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating result because $x^{-y}=1/x^y$.
     514Hence, it is important to designate exponent integral-constants as unsigned or signed: ©3 \ 3u© return an integral result, while ©3 \ 3© returns a floating result.
     515Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
     516\begin{cfa}
     517sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
     518256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
     519\end{cfa}
     520Parenthesis are necessary for the complex constants or the expresion is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
     521The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available.
     522For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©;
     523for returning a floating value, an additional divide of type ©T© into a ©double© returning a ©double© (©double ?/?( double, T )©) is necessary for negative exponents.
    503524
    504525
     
    628649\end{cfa}
    629650The ability to fall-through to the next clause \emph{is} a useful form of control flow, specifically when a sequence of case actions compound:
    630 \begin{quote2}
     651\begin{cquote}
    631652\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    632653\begin{cfa}
     
    656677\end{cfa}
    657678\end{tabular}
    658 \end{quote2}
     679\end{cquote}
    659680In this example, case 2 is always done if case 3 is done.
    660681This control flow is difficult to simulate with if statements or a ©switch© statement without fall-through as code must be duplicated or placed in a separate routine.
     
    730751        ®int y = 1;®                            §\C{// unreachable initialization}§
    731752        ®x = 7;®                                        §\C{// unreachable code without label/branch}§
    732   case 3: ...
     753  case 0: ...
    733754        ...
    734755        ®int z = 0;®                            §\C{// unreachable initialization, cannot appear after case}§
    735756        z = 2;
    736   case 3:
     757  case 1:
    737758        ®x = z;®                                        §\C{// without fall through, z is uninitialized}§
    738759}
     
    819840Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C.
    820841Therefore, the ©case© clause is extended with a list of values, as in:
    821 \begin{quote2}
     842\begin{cquote}
    822843\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    823844\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     
    849870\end{cfa}
    850871\end{tabular}
    851 \end{quote2}
     872\end{cquote}
    852873In addition, two forms of subranges are allowed to specify case values: a new \CFA form and an existing GNU C form.\footnote{
    853874The GNU C form \emph{requires} spaces around the ellipse.}
    854 \begin{quote2}
     875\begin{cquote}
    855876\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    856877\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{GNU C}}     \\
     
    882903\end{cfa}
    883904\end{tabular}
    884 \end{quote2}
     905\end{cquote}
    885906Lists of subranges are also allowed.
    886907\begin{cfa}
     
    902923}
    903924\end{C++}
    904 Since CFA is non-object-oriented, the equivalent object-oriented program looks like:
     925Since \CFA is non-object-oriented, the equivalent object-oriented program looks like:
    905926\begin{cfa}
    906927struct S { int i, j; };
    907 int mem( S &®this® ) {                  §\C{// explicit "this" parameter}§
     928int mem( S & ®this® ) {                 §\C{// explicit "this" parameter}§
    908929        ®this.®i = 1;                           §\C{// "this" is not elided}§
    909930        ®this.®j = 2;
    910931}
    911932\end{cfa}
    912 but it is cumbersome having to write "©this.©" many times in a member.
     933but it is cumbersome having to write ``©this.©'' many times in a member.
    913934
    914935\CFA provides a ©with© clause/statement (see Pascal~\cite[\S~4.F]{Pascal}) to elided the "©this.©" by opening a scope containing field identifiers, changing the qualified fields into variables and giving an opportunity for optimizing qualified references.
    915936\begin{cfa}
    916 int mem( S &this ) ®with this® { §\C{// with clause}§
    917         i = 1;                                          §\C{\color{red}// this->i}§
    918         j = 2;                                          §\C{\color{red}// this->j}§
     937int mem( S & this ) ®with this® { §\C{// with clause}§
     938        i = 1;                                          §\C{\color{red}// this.i}§
     939        j = 2;                                          §\C{\color{red}// this.j}§
    919940}
    920941\end{cfa}
     
    922943\begin{cfa}
    923944struct T { double m, n; };
    924 int mem2( S &this1, T &this2 ) ®with this1, this2® {
     945int mem2( S & this1, T & this2 ) ®with this1, this2® {
    925946        i = 1; j = 2;
    926947        m = 1.0; n = 2.0;
     
    933954        struct S1 { ... } s1;
    934955        struct S2 { ... } s2;
    935         ®with s1® {                     // with statement
     956        ®with s1® {                                     §\C{// with statement}§
    936957                // access fields of s1 without qualification
    937                 ®with s2® {  // nesting
     958                ®with s2® {                             §\C{// nesting}§
    938959                        // access fields of s1 and s2 without qualification
    939960                }
     
    10451066
    10461067
    1047 \section{Declarations}
    1048 \label{s:Declarations}
     1068\section{Alternative Declarations}
     1069\label{s:AlternativeDeclarations}
    10491070
    10501071C declaration syntax is notoriously confusing and error prone.
    10511072For example, many C programmers are confused by a declaration as simple as:
    1052 \begin{quote2}
     1073\begin{cquote}
    10531074\begin{tabular}{@{}ll@{}}
    10541075\begin{cfa}
     
    10581079\raisebox{-0.75\totalheight}{\input{Cdecl}}
    10591080\end{tabular}
    1060 \end{quote2}
     1081\end{cquote}
    10611082Is this an array of 5 pointers to integers or a \Index{pointer} to an array of 5 integers?
    1062 The fact this declaration is unclear to many C programmers means there are \Index{productivity} and \Index{safety} issues even for basic programs.
     1083If there is any doubt, it implies \Index{productivity} and \Index{safety} issues even for basic programs.
    10631084Another 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.
    10641085For example, a routine returning a \Index{pointer} to an array of integers is defined and used in the following way:
    10651086\begin{cfa}
    1066 int ®(*®f®())[®5®]® {...};                              §\C{definition}§
    1067  ... ®(*®f®())[®3®]® += 1;                              §\C{usage}§
     1087int ®(*®f®())[®5®]® {...};                              §\C{// definition}§
     1088 ... ®(*®f®())[®3®]® += 1;                              §\C{// usage}§
    10681089\end{cfa}
    10691090Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}).
     
    10741095In the following example, \R{red} is the base type and \B{blue} is qualifiers.
    10751096The \CFA declarations move the qualifiers to the left of the base type, \ie move the blue to the left of the red, while the qualifiers have the same meaning but are ordered left to right to specify a variable's type.
    1076 \begin{quote2}
     1097\begin{cquote}
    10771098\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    10781099\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     
    10891110\end{cfa}
    10901111\end{tabular}
    1091 \end{quote2}
     1112\end{cquote}
    10921113The only exception is \Index{bit field} specification, which always appear to the right of the base type.
    10931114% 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.
    10941115However, unlike C, \CFA type declaration tokens are distributed across all variables in the declaration list.
    10951116For instance, variables ©x© and ©y© of type \Index{pointer} to integer are defined in \CFA as follows:
    1096 \begin{quote2}
     1117\begin{cquote}
    10971118\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    10981119\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     
    11051126\end{cfa}
    11061127\end{tabular}
    1107 \end{quote2}
     1128\end{cquote}
    11081129The downside of this semantics is the need to separate regular and \Index{pointer} declarations:
    1109 \begin{quote2}
     1130\begin{cquote}
    11101131\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    11111132\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     
    11201141\end{cfa}
    11211142\end{tabular}
    1122 \end{quote2}
     1143\end{cquote}
    11231144which is \Index{prescribing} a safety benefit.
    11241145Other examples are:
    1125 \begin{quote2}
     1146\begin{cquote}
    11261147\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    11271148\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     
    11591180\end{cfa}
    11601181\end{tabular}
    1161 \end{quote2}
     1182\end{cquote}
    11621183
    11631184All type qualifiers, \eg ©const©, ©volatile©, etc., are used in the normal way with the new declarations and also appear left to right, \eg:
    1164 \begin{quote2}
     1185\begin{cquote}
    11651186\begin{tabular}{@{}l@{\hspace{1em}}l@{\hspace{1em}}l@{}}
    11661187\multicolumn{1}{c@{\hspace{1em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{1em}}}{\textbf{C}} \\
     
    11801201\end{cfa}
    11811202\end{tabular}
    1182 \end{quote2}
     1203\end{cquote}
    11831204All declaration qualifiers, \eg ©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}
    11841205The 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}} \eg:
    1185 \begin{quote2}
     1206\begin{cquote}
    11861207\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    11871208\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     
    12011222\end{cfa}
    12021223\end{tabular}
    1203 \end{quote2}
     1224\end{cquote}
    12041225
    12051226The new declaration syntax can be used in other contexts where types are required, \eg casts and the pseudo-routine ©sizeof©:
    1206 \begin{quote2}
     1227\begin{cquote}
    12071228\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    12081229\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    12091230\begin{cfa}
    1210 y = (®* int®)x;
    1211 i = sizeof(®[ 5 ] * int®);
     1231y = (* int)x;
     1232i = sizeof([ 5 ] * int);
    12121233\end{cfa}
    12131234&
    12141235\begin{cfa}
    1215 y = (®int *®)x;
    1216 i = sizeof(®int * [ 5 ]®);
     1236y = (int *)x;
     1237i = sizeof(int * [ 5 ]);
    12171238\end{cfa}
    12181239\end{tabular}
    1219 \end{quote2}
     1240\end{cquote}
    12201241
    12211242Finally, new \CFA declarations may appear together with C declarations in the same program block, but cannot be mixed within a specific declaration.
    12221243Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.
    1223 Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX systems.
    1224 
    1225 
    1226 \section{Exponentiation Operator}
    1227 
    1228 C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation.
    1229 \CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@\lstinline$?\?$} and ©?\=?©\index{?\\=?@\lstinline$?\=?$}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
    1230 The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©.
    1231 
    1232 As for \Index{division}, there are exponentiation operators for integral and floating-point types, including the builtin \Index{complex} types.
    1233 Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication\footnote{The multiplication computation is optimized to $O(\log y)$.} (or shifting if the base is 2).
    1234 Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating-point result because $x^{-y}=1/x^y$.
    1235 Hence, it is important to designate exponent integral-constants as unsigned or signed: ©3 \ 3u© return an integral result, while ©3 \ 3© returns a floating-point result.
    1236 Floating-point exponentiation\index{exponentiation!floating point} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
    1237 \begin{cfa}
    1238 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
    1239 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
    1240 \end{cfa}
    1241 Parenthesis are necessary for the complex constants or the expresion is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
    1242 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available.
    1243 For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©;
    1244 for returning a floating-point value, an additional divide of type ©T© into a ©double© returning a ©double© (©double ?/?( double, T )©) is necessary for negative exponents.
     1244Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX-like systems.
    12451245
    12461246
     
    12601260A program \newterm{object} is a region of data storage in the execution environment, the contents of which can represent values.
    12611261In most cases, objects are located in memory at an address, and the variable name for an object is an implicit address to the object generated by the compiler and automatically dereferenced, as in:
    1262 \begin{quote2}
     1262\begin{cquote}
    12631263\begin{tabular}{@{}ll@{\hspace{2em}}l@{}}
    12641264\begin{cfa}
     
    12781278\end{cfa}
    12791279\end{tabular}
    1280 \end{quote2}
     1280\end{cquote}
    12811281where the right example is how the compiler logically interprets the variables in the left example.
    12821282Since a variable name only points to one address during its lifetime, it is an \Index{immutable} \Index{pointer};
     
    12841284In general, variable addresses are stored in instructions instead of loaded from memory, and hence may not occupy storage.
    12851285These approaches are contrasted in the following:
    1286 \begin{quote2}
     1286\begin{cquote}
    12871287\begin{tabular}{@{}l|l@{}}
    12881288\multicolumn{1}{c|}{explicit variable address} & \multicolumn{1}{c}{implicit variable address} \\
     
    13021302\end{cfa}
    13031303\end{tabular}
    1304 \end{quote2}
     1304\end{cquote}
    13051305Finally, the immutable nature of a variable's address and the fact that there is no storage for the variable pointer means pointer assignment\index{pointer!assignment}\index{assignment!pointer} is impossible.
    13061306Therefore, the expression ©x = y© has only one meaning, ©*x = *y©, \ie manipulate values, which is why explicitly writing the dereferences is unnecessary even though it occurs implicitly as part of \Index{instruction decoding}.
     
    13091309(Similarly, an integer variable can contain multiple integer literals during its lifetime versus an integer constant representing a single literal during its lifetime, and like a variable name, may not occupy storage if the literal is embedded directly into instructions.)
    13101310Hence, a pointer occupies memory to store its current address, and the pointer's value is loaded by dereferencing, \eg:
    1311 \begin{quote2}
     1311\begin{cquote}
    13121312\begin{tabular}{@{}l@{\hspace{2em}}l@{}}
    13131313\begin{cfa}
     
    13211321\raisebox{-0.5\totalheight}{\input{pointer2.pstex_t}}
    13221322\end{tabular}
    1323 \end{quote2}
     1323\end{cquote}
    13241324
    13251325Notice, an address has a \Index{duality}\index{address!duality}: a location in memory or the value at that location.
     
    14261426The position of the ©const© qualifier \emph{after} the pointer/reference qualifier causes confuse for C programmers.
    14271427The ©const© qualifier cannot be moved before the pointer/reference qualifier for C style-declarations;
    1428 \CFA-style declarations (see \VRef{s:Declarations}) attempt to address this issue:
    1429 \begin{quote2}
     1428\CFA-style declarations (see \VRef{s:AlternativeDeclarations}) attempt to address this issue:
     1429\begin{cquote}
    14301430\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    14311431\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     
    14401440\end{cfa}
    14411441\end{tabular}
    1442 \end{quote2}
     1442\end{cquote}
    14431443where the \CFA declaration is read left-to-right.
    14441444
     
    15181518\begin{cfa}
    15191519void f( int i );
    1520 void (*fp)( int );                                      §\C{// routine pointer}§
     1520void (* fp)( int );                                     §\C{// routine pointer}§
    15211521fp = f;                                                         §\C{// reference initialization}§
    15221522fp = &f;                                                        §\C{// pointer initialization}§
     
    18971897\end{cfa}
    18981898This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
    1899 Like C, it is possible to declare multiple routine-prototypes in a single declaration, where the return type is distributed across \emph{all} routine names in the declaration list (see~\VRef{s:Declarations}), \eg:
     1899Like C, it is possible to declare multiple routine-prototypes in a single declaration, where the return type is distributed across \emph{all} routine names in the declaration list (see~\VRef{s:AlternativeDeclarations}), \eg:
    19001900\begin{cfa}
    19011901C :             const double bar1(), bar2( int ), bar3( double );
     
    20722072Default arguments and overloading (see Section 24) are complementary.
    20732073While in theory default arguments can be simulated with overloading, as in:
    2074 \begin{quote2}
     2074\begin{cquote}
    20752075\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    20762076\multicolumn{1}{c@{\hspace{3em}}}{\textbf{default arguments}}   & \multicolumn{1}{c}{\textbf{overloading}}      \\
     
    20872087\end{cfa}
    20882088\end{tabular}
    2089 \end{quote2}
     2089\end{cquote}
    20902090the number of required overloaded routines is linear in the number of default values, which is unacceptable growth.
    20912091In general, overloading should only be used over default arguments if the body of the routine is significantly different.
     
    22242224The following program in undefined in \CFA (and Indexc{gcc})
    22252225\begin{cfa}
    2226 [* [int]( int )] foo() {                §\C{// int (*foo())( int )}§
     2226[* [int]( int )] foo() {                §\C{// int (* foo())( int )}§
    22272227        int ®i® = 7;
    22282228        int bar( int p ) {
     
    22332233}
    22342234int main() {
    2235         * [int]( int ) fp = foo();      §\C{// int (*fp)( int )}§
     2235        * [int]( int ) fp = foo();      §\C{// int (* fp)( int )}§
    22362236        sout | fp( 3 ) | endl;
    22372237}
     
    22722272In the latter approach, additional return values are passed as pointer parameters.
    22732273A pointer parameter is assigned inside the routine to emulate a return.
    2274 For example, consider C's \Indexc{modf} function, which returns the integral and fractional part of a floating-point value.
     2274For example, consider C's \Indexc{modf} function, which returns the integral and fractional part of a floating value.
    22752275\begin{cfa}
    22762276double modf( double x, double * i );            §\C{// from include math.h}§
     
    29952995
    29962996The common case is printing out a sequence of variables separated by whitespace.
    2997 \begin{quote2}
     2997\begin{cquote}
    29982998\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    29992999\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
     
    30163016\end{cfa}
    30173017\end{tabular}
    3018 \end{quote2}
     3018\end{cquote}
    30193019The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators.
    30203020Similar simplification occurs for \Index{tuple} I/O, which prints all tuple values separated by ``\lstinline[showspaces=true]@, @''.
     
    30283028Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment.
    30293029Therefore, fewer output expressions require parenthesis.
    3030 \begin{quote2}
     3030\begin{cquote}
    30313031\begin{tabular}{@{}ll@{}}
    30323032\textbf{\CFA:}
     
    30473047\end{cfa}
    30483048\end{tabular}
    3049 \end{quote2}
     3049\end{cquote}
    30503050There is a weak similarity between the \CFA logical-or operator and the Shell pipe-operator for moving data, where data flows in the correct direction for input but the opposite direction for output.
    30513051
     
    34203420        int id;
    34213421        float size;
    3422         Parts *optionalParts;
     3422        Parts * optionalParts;
    34233423};
    34243424
     
    36343634
    36353635Auto type-inferencing occurs in a declaration where a variable's type is inferred from its initialization ex\-pression type.
    3636 \begin{quote2}
     3636\begin{cquote}
    36373637\begin{tabular}{@{}l@{\hspace{3em}}ll@{}}
    36383638\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CC}} & \multicolumn{1}{c}{\textbf{\Indexc{gcc}}} \\
     
    36583658\end{cfa}
    36593659\end{tabular}
    3660 \end{quote2}
     3660\end{cquote}
    36613661The two important capabilities are:
    36623662\begin{itemize}
     
    38063806
    38073807generic(type T)
    3808 typedef int (*predicate)(T);
     3808typedef int (* predicate)(T);
    38093809generic(type Captured, type T)
    3810 typedef void (*callback)(Captured, T);
     3810typedef void (* callback)(Captured, T);
    38113811
    38123812generic(type T)
    3813 void find(int length, T *array,
     3813void find(int length, T * array,
    38143814        predicate(T) p, callback(void *, T)f) {
    38153815        int i;
     
    38353835struct LinkedListElem {
    38363836        T elem;
    3837         LinkedListElem(T) *next;
     3837        LinkedListElem(T) * next;
    38383838};
    38393839
    3840 LinkedListElem *++?(LinkedListElem **elem) {
    3841         return *elem = elem->next;
     3840LinkedListElem *++?(LinkedListElem ** elem) {
     3841        return * elem = elem->next;
    38423842}
    38433843
    38443844generic (type T)
    38453845struct LinkedList {
    3846         LinkedListElem(T) *head;
     3846        LinkedListElem(T) * head;
    38473847        unsigned int size;
    38483848}
    38493849
    38503850generic (type T | bool ?==?(T, T))
    3851 bool contains(LinkedList(T) *list, T elem) {
    3852         for(LinkedListElem *iter = list->head; iter != 0; ++iter) {
     3851bool contains(LinkedList(T) * list, T elem) {
     3852        for(LinkedListElem * iter = list->head; iter != 0; ++iter) {
    38533853        if (iter->elem == elem) return true;
    38543854        }
     
    40634063// transferring requires mutual exclusion and calls deleteJob
    40644064
    4065 void transferJob(mutex Worker &from, Worker &to) {
     4065void transferJob(mutex Worker & from, Worker & to) {
    40664066        ...
    40674067        deleteJob(j);
     
    50015001#include <unistd.h>
    50025002}
    5003 size_t fileSize( const char *path ) {
     5003size_t fileSize( const char * path ) {
    50045004        struct stat s;
    50055005        stat(path, &s);
     
    50385038#[link(name = "libc")]
    50395039extern {
    5040         fn stat(path: *const u8,
    5041         buf: *mut stat_t) -> c_int;
    5042 }
    5043 fn fileSize(path: *const u8) -> size_t
     5040        fn stat(path: * const u8,
     5041        buf: * mut stat_t) -> c_int;
     5042}
     5043fn fileSize(path: * const u8) -> size_t
    50445044{
    50455045        unsafe {
     
    50635063generic(type T, type N |
    50645064        { int ?<?(N, N); })
    5065 T *maximize(N (*f)(const T&),
     5065T * maximize(N (*f)(const T&),
    50665066        int n, T *a) {
    5067         T *bestX = NULL;
     5067        T * bestX = NULL;
    50685068        N bestN;
    50695069        for (int i = 0; i < n; i++) {
     
    50775077}
    50785078
    5079 string *longest(int n, string *p)
     5079string * longest(int n, string *p)
    50805080{
    50815081        return maximize(length, n, p);
     
    50855085\begin{cfa}
    50865086template<typename T, typename F>
    5087 T *maximize(const F &f,
     5087T * maximize(const F &f,
    50885088        int n, T *a) {
    50895089        typedef decltype(f(a[0])) N;
    5090         T *bestX = NULL;
     5090        T * bestX = NULL;
    50915091        N bestN;
    50925092        for (int i = 0; i < n; i++) {
     
    51005100}
    51015101
    5102 string *longest(int n, string *p) {
     5102string * longest(int n, string *p) {
    51035103        return maximize(
    51045104        [](const string &s) {
     
    52585258\begin{cfa}
    52595259task Nonzero {
    5260         int *data;
     5260        int * data;
    52615261        int start;
    52625262        int end;
     
    57215721\CFA introduces the following new keywords.
    57225722
    5723 \begin{quote2}
     5723\begin{cquote}
    57245724\input{../refrat/keywords}
    5725 \end{quote2}
     5725\end{cquote}
    57265726
    57275727
     
    57305730
    57315731\Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list:
    5732 \begin{quote2}
     5732\begin{cquote}
    57335733\begin{tabular}{@{}llllll|l@{}}
    57345734\multicolumn{6}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
     
    57905790\end{tabular}
    57915791\end{tabular}
    5792 \end{quote2}
     5792\end{cquote}
    57935793For the prescribed head-files, \CFA uses header interposition to wraps these includes in an ©extern "C"©;
    57945794hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}).
     
    65316531The following factorial programs contrast using GMP with the \CFA and C interfaces, where the output from these programs appears in \VRef[Figure]{f:MultiPrecisionFactorials}.
    65326532(Compile with flag \Indexc{-lgmp} to link with the GMP library.)
    6533 \begin{quote2}
     6533\begin{cquote}
    65346534\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
    65356535\multicolumn{1}{c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}}      \\
     
    65636563\end{cfa}
    65646564\end{tabular}
    6565 \end{quote2}
     6565\end{cquote}
    65666566
    65676567\begin{figure}
Note: See TracChangeset for help on using the changeset viewer.