Changeset 9b71679
 Timestamp:
 Apr 25, 2021, 10:11:17 PM (3 years ago)
 Branches:
 ADT, armeh, astexperimental, enum, forallpointerdecay, jacob/cs343translation, master, newastuniqueexpr, pthreademulation, qualifiedEnum
 Children:
 aec68b6
 Parents:
 424dfc4
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

doc/user/user.tex
r424dfc4 r9b71679 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Tue Apr 20 23:25:56202114 %% Update Count : 4 88813 %% Last Modified On : Sun Apr 25 19:03:03 2021 14 %% Update Count : 4951 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 70 70 \lstset{language=CFA} % CFA default lnaguage 71 71 \lstnewenvironment{C++}[1][] % use C++ style 72 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{ @}{@},#1}}72 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®},#1}} 73 73 {} 74 74 … … 82 82 \newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}} 83 83 \newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}} 84 \newcommand{\R}[1]{ \Textbf{#1}}85 \newcommand{\R C}[1]{\Textbf{\LstBasicStyle{#1}}}84 \newcommand{\R}[1]{{\color{red}#1}} 85 \newcommand{\RB}[1]{\Textbf{#1}} 86 86 \newcommand{\B}[1]{{\Textbf[blue]{#1}}} 87 87 \newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}} … … 177 177 int main( void ) { 178 178 int x = 0, y = 1, z = 2; 179 @printf( "%d %d %d\n", x, y, z );@179 ®printf( "%d %d %d\n", x, y, z );® 180 180 } 181 181 \end{cfa} … … 186 186 int main( void ) { 187 187 int x = 0, y = 1, z = 2; 188 @sout  x  y  z;@$\indexc{sout}$188 ®sout  x  y  z;®$\indexc{sout}$ 189 189 } 190 190 \end{cfa} … … 195 195 int main() { 196 196 int x = 0, y = 1, z = 2; 197 @cout<<x<<" "<<y<<" "<<z<<endl;@197 ®cout<<x<<" "<<y<<" "<<z<<endl;® 198 198 } 199 199 \end{cfa} … … 225 225 \begin{tabular}{@{}rcccccccc@{}} 226 226 & 2021 & 2016 & 2011 & 2006 & 2001 & 1996 & 1991 & 1986 \\ \hline 227 \R {C} & \R{1} & \R{2} & \R{2} & \R{1} & \R{1} & \R{1} & \R{1} & \R{1}\\227 \RB{C} & \RB{1}& \RB{2}& \RB{2}& \RB{1}& \RB{1}& \RB{1}& \RB{1}& \RB{1}\\ 228 228 Java & 2 & 1 & 1 & 2 & 3 & 28 &  &  \\ 229 229 Python & 3 & 5 & 6 & 7 & 23 & 13 &  &  \\ … … 259 259 The signature feature of \CFA is \emph{\Index{overload}able} \Index{parametricpolymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name): 260 260 \begin{cfa} 261 @forall( otype T )@T identity( T val ) { return val; }261 ®forall( otype T )® T identity( T val ) { return val; } 262 262 int forty_two = identity( 42 ); $\C{// T is bound to int, forty\_two == 42}$ 263 263 \end{cfa} … … 323 323 Whereas, \CFA wraps each of these routines into one overloaded name ©abs©: 324 324 \begin{cfa} 325 char @abs@( char );326 extern "C" { int @abs@( int ); } $\C{// use default C routine for int}$327 long int @abs@( long int );328 long long int @abs@( long long int );329 float @abs@( float );330 double @abs@( double );331 long double @abs@( long double );332 float _Complex @abs@( float _Complex );333 double _Complex @abs@( double _Complex );334 long double _Complex @abs@( long double _Complex );325 char ®abs®( char ); 326 extern "C" { int ®abs®( int ); } $\C{// use default C routine for int}$ 327 long int ®abs®( long int ); 328 long long int ®abs®( long long int ); 329 float ®abs®( float ); 330 double ®abs®( double ); 331 long double ®abs®( long double ); 332 float _Complex ®abs®( float _Complex ); 333 double _Complex ®abs®( double _Complex ); 334 long double _Complex ®abs®( long double _Complex ); 335 335 \end{cfa} 336 336 The problem is \Index{name clash} between the C name ©abs© and the \CFA names ©abs©, resulting in two name linkages\index{C linkage}: ©extern "C"© and ©extern "Cforall"© (default). … … 359 359 The 2011 C standard plus GNU extensions. 360 360 \item 361 \Indexc[deletekeywords=inline]{fgnu89inline}\index{compilation option!fgnu89inline@{\lstinline[deletekeywords=inline] $fgnu89inline$}}361 \Indexc[deletekeywords=inline]{fgnu89inline}\index{compilation option!fgnu89inline@{\lstinline[deletekeywords=inline]{fgnu89inline}}} 362 362 Use the traditional GNU semantics for inline routines in C11 mode, which allows inline routines in header files. 363 363 \end{description} … … 531 531 Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escapemechanism: 532 532 \begin{cfa} 533 int @``@otype = 3; $\C{// make keyword an identifier}$534 double @``@forall = 3.5;533 int ®``®otype = 3; $\C{// make keyword an identifier}$ 534 double ®``®forall = 3.5; 535 535 \end{cfa} 536 536 … … 543 543 // include file uses the CFA keyword "with". 544 544 #if ! defined( with ) $\C{// nesting ?}$ 545 #define with @``@with $\C{// make keyword an identifier}$545 #define with ®``®with $\C{// make keyword an identifier}$ 546 546 #define __CFA_BFD_H__ 547 547 #endif … … 561 561 Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore} as a separator, \eg: 562 562 \begin{cfa} 563 2 @_@147@_@483@_@648; $\C{// decimal constant}$564 56 @_@ul; $\C{// decimal unsigned long constant}$565 0 @_@377; $\C{// octal constant}$566 0x @_@ff@_@ff; $\C{// hexadecimal constant}$567 0x @_@ef3d@_@aa5c; $\C{// hexadecimal constant}$568 3.141 @_@592@_@654; $\C{// floating constant}$569 10 @_@e@_@+1@_@00; $\C{// floating constant}$570 0x @_@ff@_@ff@_@p@_@3; $\C{// hexadecimal floating}$571 0x @_@1.ffff@_@ffff@_@p@_@128@_@l; $\C{// hexadecimal floating long constant}$572 L @_@$"\texttt{\textbackslash{x}}$@_@$\texttt{ff}$@_@$\texttt{ee}"$; $\C{// wide character constant}$563 2®_®147®_®483®_®648; $\C{// decimal constant}$ 564 56®_®ul; $\C{// decimal unsigned long constant}$ 565 0®_®377; $\C{// octal constant}$ 566 0x®_®ff®_®ff; $\C{// hexadecimal constant}$ 567 0x®_®ef3d®_®aa5c; $\C{// hexadecimal constant}$ 568 3.141®_®592®_®654; $\C{// floating constant}$ 569 10®_®e®_®+1®_®00; $\C{// floating constant}$ 570 0x®_®ff®_®ff®_®p®_®3; $\C{// hexadecimal floating}$ 571 0x®_®1.ffff®_®ffff®_®p®_®128®_®l; $\C{// hexadecimal floating long constant}$ 572 L®_®$"\texttt{\textbackslash{x}}$®_®$\texttt{ff}$®_®$\texttt{ee}"$; $\C{// wide character constant}$ 573 573 \end{cfa} 574 574 The rules for placement of underscores are: … … 603 603 Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative. 604 604 \begin{cfa} 605 sout  1 @\@ 0  1 @\@ 1  2 @\@ 8  4 @\@ 3  5 @\@ 3  5 @\@ 32  5L @\@ 32  5L @\@ 64  4 @\@ 3  4.0 @\@ 3  4.0 @\@2.1606  (1.0f+2.0fi) @\@(3.0f+2.0fi);607 1 1 256 64 125 @0@ 3273344365508751233 @0@ @0@0.015625 18.3791736799526 0.2647151.1922i605 sout  1 ®\® 0  1 ®\® 1  2 ®\® 8  4 ®\® 3  5 ®\® 3  5 ®\® 32  5L ®\® 32  5L ®\® 64  4 ®\® 3  4.0 ®\® 3  4.0 ®\® 2.1 606  (1.0f+2.0fi) ®\® (3.0f+2.0fi); 607 1 1 256 64 125 ®0® 3273344365508751233 ®0® ®0® 0.015625 18.3791736799526 0.2647151.1922i 608 608 \end{cfa} 609 609 Note, ©5 \ 32© and ©5L \ 64© overflow, and ©4 \ 3© is a fraction but stored in an integer so all three computations generate an integral zero. … … 613 613 \begin{cfa} 614 614 forall( otype T  { void ?{}( T & this, one_t ); T ?*?( T, T ); } ) 615 T ? @\@?( T ep, unsigned int y );615 T ?®\®?( T ep, unsigned int y ); 616 616 forall( otype T  { void ?{}( T & this, one_t ); T ?*?( T, T ); } ) 617 T ? @\@?( T ep, unsigned long int y );617 T ?®\®?( T ep, unsigned long int y ); 618 618 \end{cfa} 619 619 The user type ©T© must define multiplication, one (©1©), and ©*©. … … 625 625 626 626 627 %\subsection{\texorpdfstring{\protect\lstinline @if@/\protect\lstinline@while@Statement}{if Statement}}627 %\subsection{\texorpdfstring{\protect\lstinline{if}/\protect\lstinline{while} Statement}{if Statement}} 628 628 \subsection{\texorpdfstring{\LstKeywordStyle{if} / \LstKeywordStyle{while} Statement}{if / while Statement}} 629 629 … … 631 631 Declarations in the ©do©©while© condition are not useful because they appear after the loop body.} 632 632 \begin{cfa} 633 if ( @int x = f()@) ... $\C{// x != 0}$634 if ( @int x = f(), y = g()@) ... $\C{// x != 0 \&\& y != 0}$635 if ( @int x = f(), y = g(); x < y@) ... $\C{// relational expression}$636 if ( @struct S { int i; } x = { f() }; x.i < 4@) $\C{// relational expression}$637 638 while ( @int x = f()@) ... $\C{// x != 0}$639 while ( @int x = f(), y = g()@) ... $\C{// x != 0 \&\& y != 0}$640 while ( @int x = f(), y = g(); x < y@) ... $\C{// relational expression}$641 while ( @struct S { int i; } x = { f() }; x.i < 4@) ... $\C{// relational expression}$633 if ( ®int x = f()® ) ... $\C{// x != 0}$ 634 if ( ®int x = f(), y = g()® ) ... $\C{// x != 0 \&\& y != 0}$ 635 if ( ®int x = f(), y = g(); x < y® ) ... $\C{// relational expression}$ 636 if ( ®struct S { int i; } x = { f() }; x.i < 4® ) $\C{// relational expression}$ 637 638 while ( ®int x = f()® ) ... $\C{// x != 0}$ 639 while ( ®int x = f(), y = g()® ) ... $\C{// x != 0 \&\& y != 0}$ 640 while ( ®int x = f(), y = g(); x < y® ) ... $\C{// relational expression}$ 641 while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... $\C{// relational expression}$ 642 642 \end{cfa} 643 643 Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if©/©while© expression, and the results are combined using the logical ©&&© operator. … … 646 646 647 647 648 %\section{\texorpdfstring{\protect\lstinline @case@Clause}{case Clause}}648 %\section{\texorpdfstring{\protect\lstinline{case} Clause}{case Clause}} 649 649 \subsection{\texorpdfstring{\LstKeywordStyle{case} Clause}{case Clause}} 650 650 \label{s:caseClause} … … 659 659 \begin{cfa} 660 660 switch ( i ) { 661 case @1, 3, 5@:661 case ®1, 3, 5®: 662 662 ... 663 case @2, 4, 6@:663 case ®2, 4, 6®: 664 664 ... 665 665 } … … 686 686 \end{cquote} 687 687 In addition, subranges are allowed to specify case values.\footnote{ 688 gcc has the same mechanism but awkward syntax, \lstinline @2 ...42@, because a space is required after a number, otherwise the period is a decimal point.}688 gcc has the same mechanism but awkward syntax, \lstinline{2 ...42}, because a space is required after a number, otherwise the period is a decimal point.} 689 689 \begin{cfa} 690 690 switch ( i ) { 691 case @1~5:@$\C{// 1, 2, 3, 4, 5}$691 case ®1~5:® $\C{// 1, 2, 3, 4, 5}$ 692 692 ... 693 case @10~15:@$\C{// 10, 11, 12, 13, 14, 15}$693 case ®10~15:® $\C{// 10, 11, 12, 13, 14, 15}$ 694 694 ... 695 695 } … … 697 697 Lists of subranges are also allowed. 698 698 \begin{cfa} 699 case @1~5, 12~21, 35~42@:700 \end{cfa} 701 702 703 %\section{\texorpdfstring{\protect\lstinline @switch@Statement}{switch Statement}}699 case ®1~5, 12~21, 35~42®: 700 \end{cfa} 701 702 703 %\section{\texorpdfstring{\protect\lstinline{switch} Statement}{switch Statement}} 704 704 \subsection{\texorpdfstring{\LstKeywordStyle{switch} Statement}{switch Statement}} 705 705 … … 741 741 if ( argc == 3 ) { 742 742 // open output file 743 @// open input file744 @} else if ( argc == 2 ) {745 @// open input file (duplicate)746 747 @} else {743 ®// open input file 744 ®} else if ( argc == 2 ) { 745 ®// open input file (duplicate) 746 747 ®} else { 748 748 // usage message 749 749 } … … 756 756 \begin{cfa} 757 757 switch ( i ) { 758 @case 1: case 3: case 5:@// odd values758 ®case 1: case 3: case 5:® // odd values 759 759 // odd action 760 760 break; 761 @case 2: case 4: case 6:@// even values761 ®case 2: case 4: case 6:® // even values 762 762 // even action 763 763 break; … … 775 775 if ( j < k ) { 776 776 ... 777 @case 1:@// transfer into "if" statement777 ®case 1:® // transfer into "if" statement 778 778 ... 779 779 } // if … … 781 781 while ( j < 5 ) { 782 782 ... 783 @case 3:@// transfer into "while" statement783 ®case 3:® // transfer into "while" statement 784 784 ... 785 785 } // while … … 822 822 \begin{cfa} 823 823 switch ( x ) { 824 @int y = 1;@$\C{// unreachable initialization}$825 @x = 7;@$\C{// unreachable code without label/branch}$824 ®int y = 1;® $\C{// unreachable initialization}$ 825 ®x = 7;® $\C{// unreachable code without label/branch}$ 826 826 case 0: ... 827 827 ... 828 @int z = 0;@$\C{// unreachable initialization, cannot appear after case}$828 ®int z = 0;® $\C{// unreachable initialization, cannot appear after case}$ 829 829 z = 2; 830 830 case 1: 831 @x = z;@$\C{// without fall through, z is uninitialized}$831 ®x = z;® $\C{// without fall through, z is uninitialized}$ 832 832 } 833 833 \end{cfa} … … 861 861 Therefore, to preserve backwards compatibility, it is necessary to introduce a new kind of ©switch© statement, called ©choose©, with no implicit fallthrough semantics and an explicit fallthrough if the last statement of a caseclause ends with the new keyword ©fallthrough©/©fallthru©, \eg: 862 862 \begin{cfa} 863 @choose@( i ) {863 ®choose® ( i ) { 864 864 case 1: case 2: case 3: 865 865 ... 866 @// implicit end of switch (break)867 @case 5:866 ®// implicit end of switch (break) 867 ®case 5: 868 868 ... 869 @fallthru@; $\C{// explicit fall through}$869 ®fallthru®; $\C{// explicit fall through}$ 870 870 case 7: 871 871 ... 872 @break@$\C{// explicit end of switch (redundant)}$872 ®break® $\C{// explicit end of switch (redundant)}$ 873 873 default: 874 874 j = 3; … … 891 891 \begin{cfa} 892 892 switch ( x ) { 893 @int i = 0;@$\C{// allowed only at start}$893 ®int i = 0;® $\C{// allowed only at start}$ 894 894 case 0: 895 895 ... 896 @int j = 0;@$\C{// disallowed}$896 ®int j = 0;® $\C{// disallowed}$ 897 897 case 1: 898 898 { 899 @int k = 0;@$\C{// allowed at different nesting levels}$899 ®int k = 0;® $\C{// allowed at different nesting levels}$ 900 900 ... 901 @case 2:@$\C{// disallow case in nested statements}$901 ®case 2:® $\C{// disallow case in nested statements}$ 902 902 } 903 903 ... … … 916 916 case 3: 917 917 if ( ... ) { 918 ... @fallthru;@// goto case 4918 ... ®fallthru;® // goto case 4 919 919 } else { 920 920 ... … … 931 931 choose ( ... ) { 932 932 case 3: 933 ... @fallthrough common;@933 ... ®fallthrough common;® 934 934 case 4: 935 ... @fallthrough common;@936 937 @common:@// below fallthrough935 ... ®fallthrough common;® 936 937 ®common:® // below fallthrough 938 938 // at caseclause level 939 939 ... // common code for cases 3/4 … … 951 951 for ( ... ) { 952 952 // multilevel transfer 953 ... @fallthru common;@953 ... ®fallthru common;® 954 954 } 955 955 ... 956 956 } 957 957 ... 958 @common:@// below fallthrough958 ®common:® // below fallthrough 959 959 // at caseclause level 960 960 \end{cfa} … … 971 971 \hline 972 972 \begin{cfa} 973 while @($\,$)@{ sout  "empty"; break; }974 do { sout  "empty"; break; } while @($\,$)@;975 for @($\,$)@{ sout  "empty"; break; }976 for ( @0@) { sout  "A"; } sout  "zero";977 for ( @1@) { sout  "A"; }978 for ( @10@) { sout  "A"; }979 for ( @= 10@) { sout  "A"; }980 for ( @1 ~= 10 ~ 2@) { sout  "B"; }981 for ( @10 ~= 1 ~ 2@) { sout  "C"; }982 for ( @0.5 ~ 5.5@) { sout  "D"; }983 for ( @5.5 ~ 0.5@) { sout  "E"; }984 for ( @i; 10@) { sout  i; }985 for ( @i; = 10@) { sout  i; }986 for ( @i; 1 ~= 10 ~ 2@) { sout  i; }987 for ( @i; 10 ~= 1 ~ 2@) { sout  i; }988 for ( @i; 0.5 ~ 5.5@) { sout  i; }989 for ( @i; 5.5 ~ 0.5@) { sout  i; }990 for ( @ui; 2u ~= 10u ~ 2u@) { sout  ui; }991 for ( @ui; 10u ~= 2u ~ 2u@) { sout  ui; }973 while ®($\,$)® { sout  "empty"; break; } 974 do { sout  "empty"; break; } while ®($\,$)®; 975 for ®($\,$)® { sout  "empty"; break; } 976 for ( ®0® ) { sout  "A"; } sout  "zero"; 977 for ( ®1® ) { sout  "A"; } 978 for ( ®10® ) { sout  "A"; } 979 for ( ®= 10® ) { sout  "A"; } 980 for ( ®1 ~= 10 ~ 2® ) { sout  "B"; } 981 for ( ®10 ~= 1 ~ 2® ) { sout  "C"; } 982 for ( ®0.5 ~ 5.5® ) { sout  "D"; } 983 for ( ®5.5 ~ 0.5® ) { sout  "E"; } 984 for ( ®i; 10® ) { sout  i; } 985 for ( ®i; = 10® ) { sout  i; } 986 for ( ®i; 1 ~= 10 ~ 2® ) { sout  i; } 987 for ( ®i; 10 ~= 1 ~ 2® ) { sout  i; } 988 for ( ®i; 0.5 ~ 5.5® ) { sout  i; } 989 for ( ®i; 5.5 ~ 0.5® ) { sout  i; } 990 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout  ui; } 991 for ( ®ui; 10u ~= 2u ~ 2u® ) { sout  ui; } 992 992 enum { N = 10 }; 993 for ( @N@) { sout  "N"; }994 for ( @i; N@) { sout  i; }995 for ( @i; N ~ 0@) { sout  i; }993 for ( ®N® ) { sout  "N"; } 994 for ( ®i; N® ) { sout  i; } 995 for ( ®i; N ~ 0® ) { sout  i; } 996 996 const int start = 3, comp = 10, inc = 2; 997 for ( @i; start ~ comp ~ inc + 1@) { sout  i; }998 for ( i; 1 ~ $\R{@}$) { if ( i > 10 ) break; sout  i; }999 for ( i; 10 ~ $\R{@}$) { if ( i < 0 ) break; sout  i; }1000 for ( i; 2 ~ $\R{@}$~ 2 ) { if ( i > 10 ) break; sout  i; }1001 for ( i; 2.1 ~ $\R{@}$ ~ $\R{@}$) { if ( i > 10.5 ) break; sout  i; i += 1.7; }1002 for ( i; 10 ~ $\R{@}$~ 2 ) { if ( i < 0 ) break; sout  i; }1003 for ( i; 12.1 ~ $\R{@}$ ~ $\R{@}$) { if ( i < 2.5 ) break; sout  i; i = 1.7; }1004 for ( i; 5 @:@ j; 5 ~ $@$) { sout  i  j; }1005 for ( i; 5 @:@ j; 5 ~ $@$) { sout  i  j; }1006 for ( i; 5 @:@ j; 5 ~ $@$~ 2 ) { sout  i  j; }1007 for ( i; 5 @:@ j; 5 ~ $@$~ 2 ) { sout  i  j; }1008 for ( i; 5 @:@ j; 5 ~ $@$) { sout  i  j; }1009 for ( i; 5 @:@ j; 5 ~ $@$) { sout  i  j; }1010 for ( i; 5 @:@ j; 5 ~ $@$~ 2 ) { sout  i  j; }1011 for ( i; 5 @:@ j; 5 ~ $@$~ 2 ) { sout  i  j; }1012 for ( i; 5 @:@ j; 5 ~ $@$ ~ 2 @:@ k; 1.5 ~ $@$) { sout  i  j  k; }1013 for ( i; 5 @:@ j; 5 ~ $@$ ~ 2 @:@ k; 1.5 ~ $@$) { sout  i  j  k; }1014 for ( i; 5 @:@ k; 1.5 ~ $@$ @:@ j; 5 ~ $@$~ 2 ) { sout  i  j  k; }997 for ( ®i; start ~ comp ~ inc + 1® ) { sout  i; } 998 for ( i; 1 ~ ®@® ) { if ( i > 10 ) break; sout  i; } 999 for ( i; 10 ~ ®@® ) { if ( i < 0 ) break; sout  i; } 1000 for ( i; 2 ~ ®@® ~ 2 ) { if ( i > 10 ) break; sout  i; } 1001 for ( i; 2.1 ~ ®@® ~ ®@® ) { if ( i > 10.5 ) break; sout  i; i += 1.7; } 1002 for ( i; 10 ~ ®@® ~ 2 ) { if ( i < 0 ) break; sout  i; } 1003 for ( i; 12.1 ~ ®@® ~ ®@® ) { if ( i < 2.5 ) break; sout  i; i = 1.7; } 1004 for ( i; 5 ®:® j; 5 ~ @ ) { sout  i  j; } 1005 for ( i; 5 ®:® j; 5 ~ @ ) { sout  i  j; } 1006 for ( i; 5 ®:® j; 5 ~ @ ~ 2 ) { sout  i  j; } 1007 for ( i; 5 ®:® j; 5 ~ @ ~ 2 ) { sout  i  j; } 1008 for ( i; 5 ®:® j; 5 ~ @ ) { sout  i  j; } 1009 for ( i; 5 ®:® j; 5 ~ @ ) { sout  i  j; } 1010 for ( i; 5 ®:® j; 5 ~ @ ~ 2 ) { sout  i  j; } 1011 for ( i; 5 ®:® j; 5 ~ @ ~ 2 ) { sout  i  j; } 1012 for ( i; 5 ®:® j; 5 ~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout  i  j  k; } 1013 for ( i; 5 ®:® j; 5 ~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout  i  j  k; } 1014 for ( i; 5 ®:® k; 1.5 ~ @ ®:® j; 5 ~ @ ~ 2 ) { sout  i  j  k; } 1015 1015 \end{cfa} 1016 1016 & … … 1090 1090 The loop index is polymorphic in the type of the comparison value N (when the start value is implicit) or the start value M. 1091 1091 \begin{cfa} 1092 for ( i; @5@) $\C[2.5in]{// typeof(5) i; 5 is comparison value}$1093 for ( i; @1.5@~5.5~0.5 ) $\C{// typeof(1.5) i; 1.5 is start value}$1092 for ( i; ®5® ) $\C[2.5in]{// typeof(5) i; 5 is comparison value}$ 1093 for ( i; ®1.5®~5.5~0.5 ) $\C{// typeof(1.5) i; 1.5 is start value}$ 1094 1094 \end{cfa} 1095 1095 \item 1096 1096 An empty conditional implies comparison value of ©1© (true). 1097 1097 \begin{cfa} 1098 while ( $\R{/*empty*/}$ )$\C{// while ( true )}$1099 for ( $\R{/*empty*/}$) $\C{// for ( ; true; )}$1100 do ... while ( $\R{/*empty*/}$ )$\C{// do ... while ( true )}$1098 while ( ®/*empty*/® ) $\C{// while ( true )}$ 1099 for ( ®/*empty*/® ) $\C{// for ( ; true; )}$ 1100 do ... while ( ®/*empty*/® ) $\C{// do ... while ( true )}$ 1101 1101 \end{cfa} 1102 1102 \item 1103 1103 A comparison N is implicit upto exclusive range [0,N\R{)}. 1104 1104 \begin{cfa} 1105 for ( @5@) $\C{// for ( typeof(5) i; i < 5; i += 1 )}$1105 for ( ®5® ) $\C{// for ( typeof(5) i; i < 5; i += 1 )}$ 1106 1106 \end{cfa} 1107 1107 \item 1108 1108 A comparison ©=© N is implicit upto inclusive range [0,N\R{]}. 1109 1109 \begin{cfa} 1110 for ( @=@5 ) $\C{// for ( typeof(5) i; i <= 5; i += 1 )}$1110 for ( ®=®5 ) $\C{// for ( typeof(5) i; i <= 5; i += 1 )}$ 1111 1111 \end{cfa} 1112 1112 \item 1113 1113 The upto range M ©~©\index{~@©~©} N means exclusive range [M,N\R{)}. 1114 1114 \begin{cfa} 1115 for ( 1 @~@5 ) $\C{// for ( typeof(1) i = 1; i < 5; i += 1 )}$1115 for ( 1®~®5 ) $\C{// for ( typeof(1) i = 1; i < 5; i += 1 )}$ 1116 1116 \end{cfa} 1117 1117 \item 1118 1118 The upto range M ©~=©\index{~=@©~=©} N means inclusive range [M,N\R{]}. 1119 1119 \begin{cfa} 1120 for ( 1 @~=@5 ) $\C{// for ( typeof(1) i = 1; i <= 5; i += 1 )}$1120 for ( 1®~=®5 ) $\C{// for ( typeof(1) i = 1; i <= 5; i += 1 )}$ 1121 1121 \end{cfa} 1122 1122 \item 1123 1123 The downto range M ©~©\index{~@©~©} N means exclusive range [N,M\R{)}. 1124 1124 \begin{cfa} 1125 for ( 1 @~@5 ) $\C{// for ( typeof(1) i = 5; i > 0; i = 1 )}$1125 for ( 1®~®5 ) $\C{// for ( typeof(1) i = 5; i > 0; i = 1 )}$ 1126 1126 \end{cfa} 1127 1127 \item 1128 1128 The downto range M ©~=©\index{~=@©~=©} N means inclusive range [N,M\R{]}. 1129 1129 \begin{cfa} 1130 for ( 1 @~=@5 ) $\C{// for ( typeof(1) i = 5; i >= 0; i = 1 )}$1130 for ( 1®~=®5 ) $\C{// for ( typeof(1) i = 5; i >= 0; i = 1 )}$ 1131 1131 \end{cfa} 1132 1132 \item 1133 1133 ©@© means put nothing in this field. 1134 1134 \begin{cfa} 1135 for ( 1~ $\R{@}$~2 )$\C{// for ( typeof(1) i = 1; /*empty*/; i += 2 )}$1135 for ( 1~®@®~2 ) $\C{// for ( typeof(1) i = 1; /*empty*/; i += 2 )}$ 1136 1136 \end{cfa} 1137 1137 \item 1138 1138 ©:© means start another index. 1139 1139 \begin{cfa} 1140 for ( i; 5 @:@j; 2~12~3 ) $\C{// for ( typeof(i) i = 1, j = 2; i < 5 \&\& j < 12; i += 1, j += 3 )}\CRT$1140 for ( i; 5 ®:® j; 2~12~3 ) $\C{// for ( typeof(i) i = 1, j = 2; i < 5 \&\& j < 12; i += 1, j += 3 )}\CRT$ 1141 1141 \end{cfa} 1142 1142 \end{itemize} 1143 1143 1144 1144 1145 %\subsection{\texorpdfstring{Labelled \protect\lstinline @continue@ / \protect\lstinline@break@}{Labelled continue / break}}1145 %\subsection{\texorpdfstring{Labelled \protect\lstinline{continue} / \protect\lstinline{break}}{Labelled continue / break}} 1146 1146 \subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}} 1147 1147 … … 1158 1158 \begin{lrbox}{\myboxA} 1159 1159 \begin{cfa}[tabsize=3] 1160 @Compound:@{1161 @Try:@try {1162 @For:@for ( ... ) {1163 @While:@while ( ... ) {1164 @Do:@do {1165 @If:@if ( ... ) {1166 @Switch:@switch ( ... ) {1160 ®Compound:® { 1161 ®Try:® try { 1162 ®For:® for ( ... ) { 1163 ®While:® while ( ... ) { 1164 ®Do:® do { 1165 ®If:® if ( ... ) { 1166 ®Switch:® switch ( ... ) { 1167 1167 case 3: 1168 @break Compound@;1169 @break Try@;1170 @break For@; /* or */ @continue For@;1171 @break While@; /* or */ @continue While@;1172 @break Do@; /* or */ @continue Do@;1173 @break If@;1174 @break Switch@;1168 ®break Compound®; 1169 ®break Try®; 1170 ®break For®; /* or */ ®continue For®; 1171 ®break While®; /* or */ ®continue While®; 1172 ®break Do®; /* or */ ®continue Do®; 1173 ®break If®; 1174 ®break Switch®; 1175 1175 } // switch 1176 1176 } else { 1177 ... @break If@; ... // terminate if1177 ... ®break If®; ... // terminate if 1178 1178 } // if 1179 1179 } while ( ... ); // do 1180 1180 } // while 1181 1181 } // for 1182 } @finally@{ // always executed1182 } ®finally® { // always executed 1183 1183 } // try 1184 1184 } // compound … … 1190 1190 { 1191 1191 1192 @ForC:@for ( ... ) {1193 @WhileC:@while ( ... ) {1194 @DoC:@do {1192 ®ForC:® for ( ... ) { 1193 ®WhileC:® while ( ... ) { 1194 ®DoC:® do { 1195 1195 if ( ... ) { 1196 1196 switch ( ... ) { 1197 1197 case 3: 1198 @goto Compound@;1199 @goto Try@;1200 @goto ForB@; /* or */ @goto ForC@;1201 @goto WhileB@; /* or */ @goto WhileC@;1202 @goto DoB@; /* or */ @goto DoC@;1203 @goto If@;1204 @goto Switch@;1205 } @Switch:@;1198 ®goto Compound®; 1199 ®goto Try®; 1200 ®goto ForB®; /* or */ ®goto ForC®; 1201 ®goto WhileB®; /* or */ ®goto WhileC®; 1202 ®goto DoB®; /* or */ ®goto DoC®; 1203 ®goto If®; 1204 ®goto Switch®; 1205 } ®Switch:® ; 1206 1206 } else { 1207 ... @goto If@; ... // terminate if1208 } @If:@;1209 } while ( ... ); @DoB:@;1210 } @WhileB:@;1211 } @ForB:@;1212 1213 1214 } @Compound:@;1207 ... ®goto If®; ... // terminate if 1208 } ®If:®; 1209 } while ( ... ); ®DoB:® ; 1210 } ®WhileB:® ; 1211 } ®ForB:® ; 1212 1213 1214 } ®Compound:® ; 1215 1215 \end{cfa} 1216 1216 \end{lrbox} … … 1241 1241 1242 1242 1243 %\subsection{\texorpdfstring{\protect\lstinline @with@Statement}{with Statement}}1243 %\subsection{\texorpdfstring{\protect\lstinline{with} Statement}{with Statement}} 1244 1244 \subsection{\texorpdfstring{\LstKeywordStyle{with} Statement}{with Statement}} 1245 1245 \label{s:WithStatement} … … 1256 1256 \begin{cfa} 1257 1257 Person p 1258 @p.@name; @p.@address; @p.@sex; $\C{// access containing fields}$1258 ®p.®name; ®p.®address; ®p.®sex; $\C{// access containing fields}$ 1259 1259 \end{cfa} 1260 1260 which extends to multiple levels of qualification for nested aggregates and multiple aggregates. 1261 1261 \begin{cfa} 1262 1262 struct Ticket { ... } t; 1263 @p.name@.first; @p.address@.street; $\C{// access nested fields}$1264 @t.@departure; @t.@cost; $\C{// access multiple aggregate}$1263 ®p.name®.first; ®p.address®.street; $\C{// access nested fields}$ 1264 ®t.®departure; ®t.®cost; $\C{// access multiple aggregate}$ 1265 1265 \end{cfa} 1266 1266 Repeated aggregate qualification is tedious and makes code difficult to read. … … 1285 1285 \begin{C++} 1286 1286 struct S { 1287 char @c@; int @i@; double @d@;1287 char ®c®; int ®i®; double ®d®; 1288 1288 void f( /* S * this */ ) { $\C{// implicit ``this'' parameter}$ 1289 @c@; @i@; @d@; $\C{// this>c; this>i; this>d;}$1289 ®c®; ®i®; ®d®; $\C{// this>c; this>i; this>d;}$ 1290 1290 } 1291 1291 } … … 1295 1295 \begin{cfa} 1296 1296 struct T { 1297 char @m@; int @i@; double @n@; $\C{// derived class variables}$1297 char ®m®; int ®i®; double ®n®; $\C{// derived class variables}$ 1298 1298 }; 1299 1299 struct S : public T { 1300 char @c@; int @i@; double @d@; $\C{// class variables}$1301 void g( double @d@, T & t ) {1302 d; @t@.m; @t@.i; @t@.n; $\C{// function parameter}$1303 c; i; @this>@d; @S::@d; $\C{// class S variables}$1304 m; @T::@i; n; $\C{// class T variables}$1300 char ®c®; int ®i®; double ®d®; $\C{// class variables}$ 1301 void g( double ®d®, T & t ) { 1302 d; ®t®.m; ®t®.i; ®t®.n; $\C{// function parameter}$ 1303 c; i; ®this>®d; ®S::®d; $\C{// class S variables}$ 1304 m; ®T::®i; n; $\C{// class T variables}$ 1305 1305 } 1306 1306 }; … … 1312 1312 Hence, the qualified fields become variables with the sideeffect that it is simpler to write, easier to read, and optimize field references in a block. 1313 1313 \begin{cfa} 1314 void f( S & this ) @with ( this )@{ $\C{// with statement}$1315 @c@; @i@; @d@; $\C{// this.c, this.i, this.d}$1314 void f( S & this ) ®with ( this )® { $\C{// with statement}$ 1315 ®c®; ®i®; ®d®; $\C{// this.c, this.i, this.d}$ 1316 1316 } 1317 1317 \end{cfa} 1318 1318 with the generality of opening multiple aggregateparameters: 1319 1319 \begin{cfa} 1320 void g( S & s, T & t ) @with ( s, t )@{ $\C{// multiple aggregate parameters}$1321 c; @s.@i; d; $\C{// s.c, s.i, s.d}$1322 m; @t.@i; n; $\C{// t.m, t.i, t.n}$1320 void g( S & s, T & t ) ®with ( s, t )® { $\C{// multiple aggregate parameters}$ 1321 c; ®s.®i; d; $\C{// s.c, s.i, s.d}$ 1322 m; ®t.®i; n; $\C{// t.m, t.i, t.n}$ 1323 1323 } 1324 1324 \end{cfa} … … 1339 1339 The difference between parallel and nesting occurs for fields with the same name and type: 1340 1340 \begin{cfa} 1341 struct Q { int @i@; int k; int @m@; } q, w;1342 struct R { int @i@; int j; double @m@; } r, w;1341 struct Q { int ®i®; int k; int ®m®; } q, w; 1342 struct R { int ®i®; int j; double ®m®; } r, w; 1343 1343 with ( r, q ) { 1344 1344 j + k; $\C{// unambiguous, r.j + q.k}$ … … 1373 1373 \begin{cfa} 1374 1374 void ?{}( S & s, int i ) with ( s ) { $\C{// constructor}$ 1375 @s.i = i;@j = 3; m = 5.5; $\C{// initialize fields}$1375 ®s.i = i;® j = 3; m = 5.5; $\C{// initialize fields}$ 1376 1376 } 1377 1377 \end{cfa} … … 1386 1386 and implicitly opened \emph{after} a functionbody open, to give them higher priority: 1387 1387 \begin{cfa} 1388 void ?{}( S & s, int @i@ ) with ( s ) @with( $\emph{\R{params}}$ )@{ // syntax not allowed, illustration only1389 s.i = @i@; j = 3; m = 5.5;1388 void ?{}( S & s, int ®i® ) with ( s ) ®with( $\emph{\R{params}}$ )® { // syntax not allowed, illustration only 1389 s.i = ®i®; j = 3; m = 5.5; 1390 1390 } 1391 1391 \end{cfa} … … 1470 1470 For example, a routine returning a \Index{pointer} to an array of integers is defined and used in the following way: 1471 1471 \begin{cfa} 1472 int @(*@f@())[@5@]@{...}; $\C{// definition}$1473 ... @(*@f@())[@3@]@+= 1; $\C{// usage}$1472 int ®(*®f®())[®5®]® {...}; $\C{// definition}$ 1473 ... ®(*®f®())[®3®]® += 1; $\C{// usage}$ 1474 1474 \end{cfa} 1475 1475 Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}). … … 1487 1487 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1488 1488 \begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}] 1489 #[5] *# @int@x1;1490 #* [5]# @int@x2;1491 #[* [5] int]# f @( int p )@;1489 #[5] *# ®int® x1; 1490 #* [5]# ®int® x2; 1491 #[* [5] int]# f®( int p )®; 1492 1492 \end{cfa} 1493 1493 & 1494 1494 \begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}] 1495 @int@#*# x1 #[5]#;1496 @int@#(*#x2#)[5]#;1497 #int (*#f @( int p )@#)[5]#;1495 ®int® #*# x1 #[5]#; 1496 ®int® #(*#x2#)[5]#; 1497 #int (*#f®( int p )®#)[5]#; 1498 1498 \end{cfa} 1499 1499 \end{tabular} … … 1507 1507 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1508 1508 \begin{cfa} 1509 @*@int x, y;1509 ®*® int x, y; 1510 1510 \end{cfa} 1511 1511 & 1512 1512 \begin{cfa} 1513 int @*@x, @*@y;1513 int ®*®x, ®*®y; 1514 1514 \end{cfa} 1515 1515 \end{tabular} … … 1520 1520 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1521 1521 \begin{cfa} 1522 @*@int x;1522 ®*® int x; 1523 1523 int y; 1524 1524 \end{cfa} 1525 1525 & 1526 1526 \begin{cfa} 1527 int @*@x, y;1527 int ®*®x, y; 1528 1528 1529 1529 \end{cfa} … … 1661 1661 & 1662 1662 \begin{cfa} 1663 int * @const@x = (int *)1001663 int * ®const® x = (int *)100 1664 1664 *x = 3; // implicit dereference 1665 int * @const@y = (int *)104;1665 int * ®const® y = (int *)104; 1666 1666 *y = *x; // implicit dereference 1667 1667 \end{cfa} … … 1701 1701 \begin{tabular}{@{}l@{\hspace{2em}}l@{}} 1702 1702 \begin{cfa} 1703 int x, y, @*@ p1, @*@ p2, @**@p3;1704 p1 = @&@x; // p1 points to x1703 int x, y, ®*® p1, ®*® p2, ®**® p3; 1704 p1 = ®&®x; // p1 points to x 1705 1705 p2 = p1; // p2 points to x 1706 p1 = @&@y; // p1 points to y1706 p1 = ®&®y; // p1 points to y 1707 1707 p3 = &p2; // p3 points to p2 1708 1708 \end{cfa} … … 1730 1730 \begin{cfa} 1731 1731 p1 = p2; $\C{// pointer address assignment}$ 1732 @*@p2 = @*@p1 + x; $\C{// pointedto value assignment / operation}$1732 ®*®p2 = ®*®p1 + x; $\C{// pointedto value assignment / operation}$ 1733 1733 \end{cfa} 1734 1734 The C semantics work well for situations where manipulation of addresses is the primary meaning and data is rarely accessed, such as storage management (©malloc©/©free©). … … 1746 1746 To support this common case, a reference type is introduced in \CFA, denoted by ©&©, which is the opposite dereference semantics to a pointer type, making the value at the pointedto location the implicit semantics for dereferencing (similar but not the same as \CC \Index{reference type}s). 1747 1747 \begin{cfa} 1748 int x, y, @&@ r1, @&@ r2, @&&@r3;1749 @&@r1 = &x; $\C{// r1 points to x}$1750 @&@r2 = &r1; $\C{// r2 points to x}$1751 @&@r1 = &y; $\C{// r1 points to y}$1752 @&&@r3 = @&@&r2; $\C{// r3 points to r2}$1748 int x, y, ®&® r1, ®&® r2, ®&&® r3; 1749 ®&®r1 = &x; $\C{// r1 points to x}$ 1750 ®&®r2 = &r1; $\C{// r2 points to x}$ 1751 ®&®r1 = &y; $\C{// r1 points to y}$ 1752 ®&&®r3 = ®&®&r2; $\C{// r3 points to r2}$ 1753 1753 r2 = ((r1 + r2) * (r3  r1)) / (r3  15); $\C{// implicit dereferencing}$ 1754 1754 \end{cfa} … … 1757 1757 One way to conceptualize a reference is via a rewrite rule, where the compiler inserts a dereference operator before the reference variable for each reference qualifier in a declaration, so the previous example becomes: 1758 1758 \begin{cfa} 1759 @*@r2 = ((@*@r1 + @*@r2) @*@ (@**@r3  @*@r1)) / (@**@r3  15);1759 ®*®r2 = ((®*®r1 + ®*®r2) ®*® (®**®r3  ®*®r1)) / (®**®r3  15); 1760 1760 \end{cfa} 1761 1761 When a reference operation appears beside a dereference operation, \eg ©&*©, they cancel out. … … 1766 1766 For a \CFA reference type, the cancellation on the lefthand side of assignment leaves the reference as an address (\Index{lvalue}): 1767 1767 \begin{cfa} 1768 (& @*@)r1 = &x; $\C{// (\&*) cancel giving address in r1 not variable pointedto by r1}$1768 (&®*®)r1 = &x; $\C{// (\&*) cancel giving address in r1 not variable pointedto by r1}$ 1769 1769 \end{cfa} 1770 1770 Similarly, the address of a reference can be obtained for assignment or computation (\Index{rvalue}): 1771 1771 \begin{cfa} 1772 (&(& @*@)@*@)r3 = &(&@*@)r2; $\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}$1772 (&(&®*®)®*®)r3 = &(&®*®)r2; $\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}$ 1773 1773 \end{cfa} 1774 1774 Cancellation\index{cancellation!pointer/reference}\index{pointer!cancellation} works to arbitrary depth. … … 1793 1793 const int cx = 5; $\C{// cannot change cx;}$ 1794 1794 const int & cr = cx; $\C{// cannot change what cr points to}$ 1795 @&@cr = &cx; $\C{// can change cr}$1795 ®&®cr = &cx; $\C{// can change cr}$ 1796 1796 cr = 7; $\C{// error, cannot change cx}$ 1797 1797 int & const rc = x; $\C{// must be initialized}$ 1798 @&@rc = &x; $\C{// error, cannot change rc}$1798 ®&®rc = &x; $\C{// error, cannot change rc}$ 1799 1799 const int & const crc = cx; $\C{// must be initialized}$ 1800 1800 crc = 7; $\C{// error, cannot change cx}$ 1801 @&@crc = &cx; $\C{// error, cannot change crc}$1801 ®&®crc = &cx; $\C{// error, cannot change crc}$ 1802 1802 \end{cfa} 1803 1803 Hence, for type ©& const©, there is no pointer assignment, so ©&rc = &x© is disallowed, and \emph{the address value cannot be the null pointer unless an arbitrary pointer is coerced\index{coercion} into the reference}: … … 1820 1820 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1821 1821 \begin{cfa} 1822 @const@ * @const@* const int ccp;1823 @const@ & @const@& const int ccr;1822 ®const® * ®const® * const int ccp; 1823 ®const® & ®const® & const int ccr; 1824 1824 \end{cfa} 1825 1825 & 1826 1826 \begin{cfa} 1827 const int * @const@ * @const@ccp;1827 const int * ®const® * ®const® ccp; 1828 1828 1829 1829 \end{cfa} … … 1857 1857 \begin{cfa} 1858 1858 int * p = &x; $\C{// assign address of x}$ 1859 @int * p = x;@$\C{// assign value of x}$1859 ®int * p = x;® $\C{// assign value of x}$ 1860 1860 int & r = x; $\C{// must have address of x}$ 1861 1861 \end{cfa} … … 1881 1881 When a pointer/reference parameter has a ©const© value (immutable), it is possible to pass literals and expressions. 1882 1882 \begin{cfa} 1883 void f( @const@int & cr );1884 void g( @const@int * cp );1885 f( 3 ); g( @&@3 );1886 f( x + y ); g( @&@(x + y) );1883 void f( ®const® int & cr ); 1884 void g( ®const® int * cp ); 1885 f( 3 ); g( ®&®3 ); 1886 f( x + y ); g( ®&®(x + y) ); 1887 1887 \end{cfa} 1888 1888 Here, the compiler passes the address to the literal 3 or the temporary for the expression ©x + y©, knowing the argument cannot be changed through the parameter. … … 1895 1895 void f( int & r ); 1896 1896 void g( int * p ); 1897 f( 3 ); g( @&@3 ); $\C{// compiler implicit generates temporaries}$1898 f( x + y ); g( @&@(x + y) ); $\C{// compiler implicit generates temporaries}$1897 f( 3 ); g( ®&®3 ); $\C{// compiler implicit generates temporaries}$ 1898 f( x + y ); g( ®&®(x + y) ); $\C{// compiler implicit generates temporaries}$ 1899 1899 \end{cfa} 1900 1900 Essentially, there is an implicit \Index{rvalue} to \Index{lvalue} conversion in this case.\footnote{ … … 1917 1917 Instead, a routine object should be referenced by a ©const© reference: 1918 1918 \begin{cfa} 1919 @const@ void (@&@fr)( int ) = f; $\C{// routine reference}$1919 ®const® void (®&® fr)( int ) = f; $\C{// routine reference}$ 1920 1920 fr = ... $\C{// error, cannot change code}$ 1921 1921 &fr = ...; $\C{// changing routine reference}$ … … 1979 1979 \begin{cfa} 1980 1980 int x, &r = x, f( int p ); 1981 x = @r@ + f( @r@); $\C{// lvalue reference converts to rvalue}$1981 x = ®r® + f( ®r® ); $\C{// lvalue reference converts to rvalue}$ 1982 1982 \end{cfa} 1983 1983 An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped. 1984 1984 1985 1985 \item 1986 lvalue to reference conversion: \lstinline[deletekeywords=lvalue] @lvaluetype cv1 T@converts to ©cv2 T &©, which allows implicitly converting variables to references.1987 \begin{cfa} 1988 int x, &r = @x@, f( int & p ); $\C{// lvalue variable (int) convert to reference (int \&)}$1989 f( @x@); $\C{// lvalue variable (int) convert to reference (int \&)}$1986 lvalue to reference conversion: \lstinline[deletekeywords=lvalue]{lvaluetype cv1 T} converts to ©cv2 T &©, which allows implicitly converting variables to references. 1987 \begin{cfa} 1988 int x, &r = ®x®, f( int & p ); $\C{// lvalue variable (int) convert to reference (int \&)}$ 1989 f( ®x® ); $\C{// lvalue variable (int) convert to reference (int \&)}$ 1990 1990 \end{cfa} 1991 1991 Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost. … … 1997 1997 \begin{cfa} 1998 1998 int x, & f( int & p ); 1999 f( @x + 3@); $\C[1.5in]{// rvalue parameter (int) implicitly converts to lvalue temporary reference (int \&)}$2000 @&f@(...) = &x; $\C{// rvalue result (int \&) implicitly converts to lvalue temporary reference (int \&)}\CRT$1999 f( ®x + 3® ); $\C[1.5in]{// rvalue parameter (int) implicitly converts to lvalue temporary reference (int \&)}$ 2000 ®&f®(...) = &x; $\C{// rvalue result (int \&) implicitly converts to lvalue temporary reference (int \&)}\CRT$ 2001 2001 \end{cfa} 2002 2002 In both case, modifications to the temporary are inaccessible (\Index{warning}). … … 2224 2224 \CFA allows other integral types with associated values. 2225 2225 \begin{cfa} 2226 enum( @char@ ) Letter { A @= 'A'@, B, C, I @= 'I'@, J, K };2227 enum( @long long int@) BigNum { X = 123_456_789_012_345, Y = 345_012_789_456_123 };2226 enum( ®char® ) Letter { A ®= 'A'®, B, C, I ®= 'I'®, J, K }; 2227 enum( ®long long int® ) BigNum { X = 123_456_789_012_345, Y = 345_012_789_456_123 }; 2228 2228 \end{cfa} 2229 2229 For enumeration ©Letter©, enum ©A©'s value is explicitly set to ©'A'©, with ©B© and ©C© implicitly numbered with increasing values from ©'A'©, and similarly for enums ©I©, ©J©, and ©K©. … … 2232 2232 \begin{cfa} 2233 2233 // nonintegral numeric 2234 enum( @double@) Math { PI_2 = 1.570796, PI = 3.141597, E = 2.718282 }2234 enum( ®double® ) Math { PI_2 = 1.570796, PI = 3.141597, E = 2.718282 } 2235 2235 // pointer 2236 enum( @char *@) Name { Fred = "Fred", Mary = "Mary", Jane = "Jane" };2236 enum( ®char *® ) Name { Fred = "Fred", Mary = "Mary", Jane = "Jane" }; 2237 2237 int i, j, k; 2238 enum( @int *@) ptr { I = &i, J = &j, K = &k };2239 enum( @int &@) ref { I = i, J = j, K = k };2238 enum( ®int *® ) ptr { I = &i, J = &j, K = &k }; 2239 enum( ®int &® ) ref { I = i, J = j, K = k }; 2240 2240 // tuple 2241 enum( @[int, int]@) { T = [ 1, 2 ] };2241 enum( ®[int, int]® ) { T = [ 1, 2 ] }; 2242 2242 // function 2243 2243 void f() {...} void g() {...} 2244 enum( @void (*)()@) funs { F = f, F = g };2244 enum( ®void (*)()® ) funs { F = f, F = g }; 2245 2245 // aggregate 2246 2246 struct S { int i, j; }; 2247 enum( @S@) s { A = { 3, 4 }, B = { 7, 8 } };2247 enum( ®S® ) s { A = { 3, 4 }, B = { 7, 8 } }; 2248 2248 // enumeration 2249 enum( @Letter@) Greek { Alph = A, Beta = B, /* more enums */ }; // alphabet intersection2249 enum( ®Letter® ) Greek { Alph = A, Beta = B, /* more enums */ }; // alphabet intersection 2250 2250 \end{cfa} 2251 2251 Enumeration ©Greek© may have more or less enums than ©Letter©, but the enum values \emph{must} be from ©Letter©. … … 2270 2270 A fallback is explicit Cstyle initialization using ©@=©. 2271 2271 \begin{cfa} 2272 enum( struct vec3 ) Axis { Up $@$= { 1, 0, 0 }, Left $@$= { 0, 1, 0 }, Front $@$= { 0, 0, 1 } }2272 enum( struct vec3 ) Axis { Up @= { 1, 0, 0 }, Left @= { 0, 1, 0 }, Front @= { 0, 0, 1 } } 2273 2273 \end{cfa} 2274 2274 Finally, enumeration variables are assignable and comparable only if the appropriate operators are defined for its enum type. … … 2279 2279 \Index{Plan9}\index{inheritance!enumeration} inheritance may be used with enumerations. 2280 2280 \begin{cfa} 2281 enum( char * ) Name2 { @inline Name@, Jack = "Jack", Jill = "Jill" };2282 enum @/* inferred */@ Name3 { @inline Name2@, Sue = "Sue", Tom = "Tom" };2281 enum( char * ) Name2 { ®inline Name®, Jack = "Jack", Jill = "Jill" }; 2282 enum ®/* inferred */® Name3 { ®inline Name2®, Sue = "Sue", Tom = "Tom" }; 2283 2283 \end{cfa} 2284 2284 Enumeration ©Name2© inherits all the enums and their values from enumeration ©Name© by containment, and a ©Name© enumeration is a subtype of enumeration ©Name2©. … … 2353 2353 The point of the new syntax is to allow returning multiple values from a routine~\cite{Galletly96,CLU}, \eg: 2354 2354 \begin{cfa} 2355 @[ int o1, int o2, char o3 ]@f( int i1, char i2, char i3 ) {2355 ®[ int o1, int o2, char o3 ]® f( int i1, char i2, char i3 ) { 2356 2356 $\emph{routine body}$ 2357 2357 } … … 2365 2365 Declaration qualifiers can only appear at the start of a routine definition, \eg: 2366 2366 \begin{cfa} 2367 @extern@[ int x ] g( int y ) {$\,$}2367 ®extern® [ int x ] g( int y ) {$\,$} 2368 2368 \end{cfa} 2369 2369 Lastly, if there are no output parameters or input parameters, the brackets and/or parentheses must still be specified; … … 2423 2423 \begin{minipage}{\linewidth} 2424 2424 \begin{cfa} 2425 @[ int x, int y ]@f() {2425 ®[ int x, int y ]® f() { 2426 2426 int z; 2427 2427 ... x = 0; ... y = z; ... 2428 @return;@$\C{// implicitly return x, y}$2428 ®return;® $\C{// implicitly return x, y}$ 2429 2429 } 2430 2430 \end{cfa} … … 2758 2758 2759 2759 int fred() { 2760 s.t.c = @S.@R; // type qualification2761 struct @S.@T t = { @S.@R, 1, 2 };2762 enum @S.@C c;2763 union @S.T.@U u;2760 s.t.c = ®S.®R; // type qualification 2761 struct ®S.®T t = { ®S.®R, 1, 2 }; 2762 enum ®S.®C c; 2763 union ®S.T.®U u; 2764 2764 } 2765 2765 \end{cfa} … … 2787 2787 qsort( ia, size ); $\C{// sort ascending order using builtin ?<?}$ 2788 2788 { 2789 @int ?<?( int x, int y ) { return x > y; }@$\C{// nested routine}$2789 ®int ?<?( int x, int y ) { return x > y; }® $\C{// nested routine}$ 2790 2790 qsort( ia, size ); $\C{// sort descending order by local redefinition}$ 2791 2791 } … … 2797 2797 \begin{cfa} 2798 2798 [* [int]( int )] foo() { $\C{// int (* foo())( int )}$ 2799 int @i@= 7;2799 int ®i® = 7; 2800 2800 int bar( int p ) { 2801 @i@+= 1; $\C{// dependent on local variable}$2802 sout  @i@;2801 ®i® += 1; $\C{// dependent on local variable}$ 2802 sout  ®i®; 2803 2803 } 2804 2804 return bar; $\C{// undefined because of local dependence}$ … … 2818 2818 In C and \CFA, lists of elements appear in several contexts, such as the parameter list of a routine call. 2819 2819 \begin{cfa} 2820 f( @2, x, 3 + i@); $\C{// element list}$2820 f( ®2, x, 3 + i® ); $\C{// element list}$ 2821 2821 \end{cfa} 2822 2822 A list of elements is called a \newterm{tuple}, and is different from a \Index{comma expression}. … … 2931 2931 In \CFA, it is possible to overcome this restriction by declaring a \newterm{tuple variable}. 2932 2932 \begin{cfa} 2933 [int, int] @qr@= div( 13, 5 ); $\C{// initialize tuple variable}$2934 printf( "%d %d\n", @qr@); $\C{// print quotient/remainder}$2933 [int, int] ®qr® = div( 13, 5 ); $\C{// initialize tuple variable}$ 2934 printf( "%d %d\n", ®qr® ); $\C{// print quotient/remainder}$ 2935 2935 \end{cfa} 2936 2936 It is now possible to match the multiple returnvalues to a single variable, in much the same way as \Index{aggregation}. … … 3596 3596 \begin{cfa} 3597 3597 int x = 1, y = 2, z = 3; 3598 sout  x @@ y @@z;3598 sout  x ®® y ®® z; 3599 3599 \end{cfa} 3600 3600 & 3601 3601 \begin{cfa} 3602 3602 3603 cout << x @<< " "@ << y @<< " "@<< z << endl;3603 cout << x ®<< " "® << y ®<< " "® << z << endl; 3604 3604 \end{cfa} 3605 3605 & … … 3610 3610 \\ 3611 3611 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3612 1 @ @2@ @33612 1® ®2® ®3 3613 3613 \end{cfa} 3614 3614 & 3615 3615 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3616 1 @ @2@ @33616 1® ®2® ®3 3617 3617 \end{cfa} 3618 3618 & 3619 3619 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3620 1 @ @2@ @33620 1® ®2® ®3 3621 3621 \end{cfa} 3622 3622 \end{tabular} 3623 3623 \end{cquote} 3624 3624 The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators and newline. 3625 Similar simplification occurs for \Index{tuple} I/O, which flattens the tuple and prints each value separated by ``\lstinline[showspaces=true] @, @''.3625 Similar simplification occurs for \Index{tuple} I/O, which flattens the tuple and prints each value separated by ``\lstinline[showspaces=true]{, }''. 3626 3626 \begin{cfa} 3627 3627 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; … … 3629 3629 \end{cfa} 3630 3630 \begin{cfa}[showspaces=true,aboveskip=0pt] 3631 1 @, @2@, @3 4@, @5@, @63631 1®, ®2®, ®3 4®, ®5®, ®6 3632 3632 \end{cfa} 3633 3633 Finally, \CFA uses the logicalor operator for I/O as it is the lowestpriority \emph{overloadable} operator, other than assignment. … … 3638 3638 & 3639 3639 \begin{cfa} 3640 sout  x * 3  y + 1  z << 2  x == y  @(@x  y@)@  @(@x  y@)@  @(@x > z ? 1 : 2@)@;3640 sout  x * 3  y + 1  z << 2  x == y  ®(®x  y®)®  ®(®x  y®)®  ®(®x > z ? 1 : 2®)®; 3641 3641 \end{cfa} 3642 3642 \\ … … 3644 3644 & 3645 3645 \begin{cfa} 3646 cout << x * 3 << y + 1 << @(@z << 2@)@ << @(@x == y@)@ << @(@x  y@)@ << @(@x  y@)@ << @(@x > z ? 1 : 2@)@<< endl;3646 cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << ®(®x  y®)® << ®(®x  y®)® << ®(®x > z ? 1 : 2®)® << endl; 3647 3647 \end{cfa} 3648 3648 \\ … … 3679 3679 \\ 3680 3680 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3681 @1@ @2.5@ @A@ 3681 ®1® ®2.5® ®A® 3682 3682 3683 3683 … … 3685 3685 & 3686 3686 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3687 @1@ @2.5@ @A@ 3687 ®1® ®2.5® ®A® 3688 3688 3689 3689 … … 3691 3691 & 3692 3692 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3693 @1@ 3694 @2.5@ 3695 @A@ 3693 ®1® 3694 ®2.5® 3695 ®A® 3696 3696 \end{cfa} 3697 3697 \end{tabular} … … 3729 3729 3730 3730 \item 3731 A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \LstStringStyle{,.;!?)]\}\%\textcent\guillemotright}, where \LstStringStyle{\guillemotright} a closing citation mark.3731 A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \LstStringStyle{,.;!?)]\}\%\textcent\guillemotright}, where \LstStringStyle{\guillemotright} is a closing citation mark. 3732 3732 \begin{cfa} 3733 3733 sout  1  ", x"  2  ". x"  3  "; x"  4  "! x"  5  "? x"  6  "% x" … … 3735 3735 \end{cfa} 3736 3736 \begin{cfa}[showspaces=true] 3737 1 @,@ x 2@.@ x 3@;@ x 4@!@ x 5@?@ x 6@%@ x 7$\R{\LstStringStyle{\textcent}}$ x 8$\R{\LstStringStyle{\guillemotright}}$ x 9@)@ x 10@]@ x 11@}@x3737 1®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7$\R{\LstStringStyle{\textcent}}$ x 8$\R{\LstStringStyle{\guillemotright}}$ x 9®)® x 10®]® x 11®}® x 3738 3738 \end{cfa} 3739 3739 … … 3742 3742 %$ 3743 3743 \begin{cfa} 3744 sout  "x ("  1  "x ["  2  "x {"  3  "x ="  4  "x $ "  5  "x $\LstStringStyle{\textsterling}$"  6  "x $\LstStringStyle{\textyen}$"3744 sout  "x ("  1  "x ["  2  "x {"  3  "x ="  4  "x $\LstStringStyle{\textdollar}$"  5  "x $\LstStringStyle{\textsterling}$"  6  "x $\LstStringStyle{\textyen}$" 3745 3745  7  "x $\LstStringStyle{\textexclamdown}$"  8  "x $\LstStringStyle{\textquestiondown}$"  9  "x $\LstStringStyle{\guillemotleft}$"  10; 3746 3746 \end{cfa} 3747 3747 %$ 3748 3748 \begin{cfa}[showspaces=true] 3749 x @(@1 x @[@2 x @{@3 x @=@4 x $\LstStringStyle{\textdollar}$5 x $\R{\LstStringStyle{\textsterling}}$6 x $\R{\LstStringStyle{\textyen}}$7 x $\R{\LstStringStyle{\textexclamdown}}$8 x $\R{\LstStringStyle{\textquestiondown}}$9 x $\R{\LstStringStyle{\guillemotleft}}$103749 x ®(®1 x ®[®2 x ®{®3 x ®=®4 x $\LstStringStyle{\textdollar}$5 x $\R{\LstStringStyle{\textsterling}}$6 x $\R{\LstStringStyle{\textyen}}$7 x $\R{\LstStringStyle{\textexclamdown}}$8 x $\R{\LstStringStyle{\textquestiondown}}$9 x $\R{\LstStringStyle{\guillemotleft}}$10 3750 3750 \end{cfa} 3751 3751 %$ 3752 3752 3753 3753 \item 3754 A sep erator does not appear before/after a C string starting/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]{`'": \t\v\f\r\n}3754 A separator does not appear before/after a C string starting/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]{`'": \t\v\f\r\n} 3755 3755 \begin{cfa} 3756 3756 sout  "x`"  1  "`x'"  2  "'x\""  3  "\"x:"  4  ":x "  5  " x\t"  6  "\tx"; 3757 3757 \end{cfa} 3758 3758 \begin{cfa}[showspaces=true,showtabs=true] 3759 x @`@1@`@x$\R{\texttt{'}}$2$\R{\texttt{'}}$x$\R{\texttt{"}}$3$\R{\texttt{"}}$x@:@4@:@x@ @5@ @x@ @6@ @x3759 x®`®1®`®x$\R{\texttt{'}}$2$\R{\texttt{'}}$x$\R{\texttt{"}}$3$\R{\texttt{"}}$x®:®4®:®x® ®5® ®x® ®6® ®x 3760 3760 \end{cfa} 3761 3761 … … 3766 3766 \end{cfa} 3767 3767 \begin{cfa}[showspaces=true,showtabs=true] 3768 x ( @ @1@ @) x 2@ @, x 3@ @:x:@ @43768 x (® ®1® ®) x 2® ®, x 3® ®:x:® ®4 3769 3769 \end{cfa} 3770 3770 \end{enumerate} … … 3779 3779 \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sep}\index{manipulator!sep@©sep©}/\Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string. 3780 3780 The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters). 3781 \begin{cfa}[escapechar=off,belowskip=0pt] 3782 sepSet( sout, ", $" ); $\C{// set separator from " " to ", \$"}$ 3783 sout  1  2  3  " \""  @sep@  "\""; 3784 \end{cfa} 3785 %$ 3786 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 3787 1@, $@2@, $@3 @", $"@ 3788 \end{cfa} 3789 %$ 3781 \begin{cfa}[belowskip=0pt] 3782 sepSet( sout, ", $\LstStringStyle{\textdollar}$" ); $\C{// set separator from " " to ", \$"}$ 3783 sout  1  2  3  " \""  ®sep®  "\""; 3784 \end{cfa} 3785 \begin{cfa}[showspaces=true,aboveskip=0pt] 3786 1®, $\LstStringStyle{\textdollar}$®2®, $\LstStringStyle{\textdollar}$®3 ®", $\LstStringStyle{\textdollar}$"® 3787 \end{cfa} 3790 3788 \begin{cfa}[belowskip=0pt] 3791 3789 sepSet( sout, " " ); $\C{// reset separator to " "}$ 3792 sout  1  2  3  " \""  @sepGet( sout )@ "\"";3790 sout  1  2  3  " \""  ®sepGet( sout )®  "\""; 3793 3791 \end{cfa} 3794 3792 \begin{cfa}[showspaces=true,aboveskip=0pt] 3795 1 @ @2@ @3 @" "@3793 1® ®2® ®3 ®" "® 3796 3794 \end{cfa} 3797 3795 ©sepGet© can be used to store a separator and then restore it: 3798 3796 \begin{cfa}[belowskip=0pt] 3799 char store[ @sepSize@]; $\C{// sepSize is the maximum separator size}$3797 char store[®sepSize®]; $\C{// sepSize is the maximum separator size}$ 3800 3798 strcpy( store, sepGet( sout ) ); $\C{// copy current separator}$ 3801 3799 sepSet( sout, "_" ); $\C{// change separator to underscore}$ … … 3803 3801 \end{cfa} 3804 3802 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3805 1 @_@2@_@33803 1®_®2®_®3 3806 3804 \end{cfa} 3807 3805 \begin{cfa}[belowskip=0pt] … … 3810 3808 \end{cfa} 3811 3809 \begin{cfa}[showspaces=true,aboveskip=0pt] 3812 1 @ @2@ @33810 1® ®2® ®3 3813 3811 \end{cfa} 3814 3812 … … 3818 3816 \begin{cfa}[belowskip=0pt] 3819 3817 sepSetTuple( sout, " " ); $\C{// set tuple separator from ", " to " "}$ 3820 sout  t1  t2  " \""  @sepTuple@ "\"";3818 sout  t1  t2  " \""  ®sepTuple®  "\""; 3821 3819 \end{cfa} 3822 3820 \begin{cfa}[showspaces=true,aboveskip=0pt] 3823 1 2 3 4 5 6 @" "@3821 1 2 3 4 5 6 ®" "® 3824 3822 \end{cfa} 3825 3823 \begin{cfa}[belowskip=0pt] 3826 3824 sepSetTuple( sout, ", " ); $\C{// reset tuple separator to ", "}$ 3827 sout  t1  t2  " \""  @sepGetTuple( sout )@ "\"";3825 sout  t1  t2  " \""  ®sepGetTuple( sout )®  "\""; 3828 3826 \end{cfa} 3829 3827 \begin{cfa}[showspaces=true,aboveskip=0pt] 3830 1, 2, 3 4, 5, 6 @", "@3828 1, 2, 3 4, 5, 6 ®", "® 3831 3829 \end{cfa} 3832 3830 As for ©sepGet©, ©sepGetTuple© can be use to store a tuple separator and then restore it. … … 3880 3878 \end{cfa} 3881 3879 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3882 @ @1 2 3@ @ 3880 ® ®1 2 3® ® 3883 3881 \end{cfa} 3884 3882 \end{enumerate} … … 3900 3898 For example, in: 3901 3899 \begin{cfa} 3902 sin  i  @nl@ j;3903 1 @2@3900 sin  i  ®nl®  j; 3901 1 ®2® 3904 3902 3 3905 3903 \end{cfa} … … 3942 3940 0b0 0b11011 0b11011 0b11011 0b11011 3943 3941 sout  bin( 27HH )  bin( 27H )  bin( 27 )  bin( 27L ); 3944 0b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b @(58 1s)@1001013942 0b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b®(58 1s)®100101 3945 3943 \end{cfa} 3946 3944 … … 3978 3976 3979 3977 \item 3978 \Indexc{eng}( floatingpoint )\index{manipulator!eng@©eng©} print value in engineering notation with exponent, which means the exponent is adjusted to a multiple of 3. 3979 \begin{cfa}[belowskip=0pt] 3980 sout  eng( 0.0 )  eng( 27000.5 )  eng( 27.5e7 ); 3981 0®e0® 27.0005®e3® 275®e6® 3982 \end{cfa} 3983 3984 \item 3985 \Indexc{unit}( engineeringnotation )\index{manipulator!unit@©unit©} print engineering exponent as a letter between the range $10^{24}$ and $10^{24}$: 3986 ©y© $\Rightarrow 10^{24}$, ©z© $\Rightarrow 10^{21}$, ©a© $\Rightarrow 10^{18}$, ©f© $\Rightarrow 10^{15}$, ©p© $\Rightarrow 10^{12}$, ©n© $\Rightarrow 10^{9}$, ©u© $\Rightarrow 10^{6}$, ©m© $\Rightarrow 10^{3}$, ©K© $\Rightarrow 10^{3}$, ©M© $\Rightarrow 10^{6}$, ©G© $\Rightarrow 10^{9}$, ©T© $\Rightarrow 10^{12}$, ©P© $\Rightarrow 10^{15}$, ©E© $\Rightarrow 10^{18}$, ©Z© $\Rightarrow 10^{21}$, ©Y© $\Rightarrow 10^{24}$. 3987 For exponent $10^{0}$, no decimal point or letter is printed. 3988 \begin{cfa}[belowskip=0pt] 3989 sout  unit(eng( 0.0 ))  unit(eng( 27000.5 ))  unit(eng( 27.5e7 )); 3990 0 27.0005®K® 275®M® 3991 \end{cfa} 3992 3993 \item 3980 3994 \Indexc{upcase}( bin / hex / floatingpoint )\index{manipulator!upcase@©upcase©} print letters in a value in upper case. Lower case is the default. 3981 3995 \begin{cfa}[belowskip=0pt] 3982 3996 sout  upcase( bin( 27 ) )  upcase( hex( 27 ) )  upcase( 27.5e10 )  upcase( hex( 27.5 ) ); 3983 0 @B@11011 0@X@1@B@ 2.75@E@09 0@X@1.@B@8@P@+43997 0®B®11011 0®X®1®B® 2.75®E®09 0®X®1.®B®8®P®+4 3984 3998 \end{cfa} 3985 3999 … … 3997 4011 \begin{cfa}[belowskip=0pt] 3998 4012 sout  0.  nodp( 0. )  27.0  nodp( 27.0 )  nodp( 27.5 ); 3999 0.0 @0@ 27.0 @27@27.54013 0.0 ®0® 27.0 ®27® 27.5 4000 4014 \end{cfa} 4001 4015 … … 4004 4018 \begin{cfa}[belowskip=0pt] 4005 4019 sout  sign( 27 )  sign( 27 )  sign( 27. )  sign( 27. )  sign( 27.5 )  sign( 27.5 ); 4006 @+@27 27 @+@27.0 27.0 @+@27.5 27.54007 \end{cfa} 4008 4009 \item 4010 \Indexc{wd} ©( unsigned char minimum, T val )©\index{manipulator!wd@©wd©}, ©wd( unsigned char minimum, unsigned char precision, T val )©4011 For all types, ©minimum© is the minimumnumber of printed characters.4020 ®+®27 27 ®+®27.0 27.0 ®+®27.5 27.5 4021 \end{cfa} 4022 4023 \item 4024 \Indexc{wd}( minimum, value )\index{manipulator!wd@©wd©}, ©wd©( minimum, precision, value ) 4025 For all types, minimum is the number of printed characters. 4012 4026 If the value is shorter than the minimum, it is padded on the right with spaces. 4013 4027 \begin{cfa}[belowskip=0pt] … … 4017 4031 \end{cfa} 4018 4032 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4019 @ @34 @ @34 344020 @ @4.000000 @ @4.000000 4.0000004021 @ @ab @ @ab ab4022 \end{cfa} 4023 If the value is larger, it is printed without truncation, ignoring the ©minimum©.4033 ® ®34 ® ®34 34 4034 ® ®4.000000 ® ®4.000000 4.000000 4035 ® ®ab ® ®ab ab 4036 \end{cfa} 4037 If the value is larger, it is printed without truncation, ignoring the minimum. 4024 4038 \begin{cfa}[belowskip=0pt] 4025 4039 sout  wd( 4, 34567 )  wd( 3, 34567 )  wd( 2, 34567 ); … … 4028 4042 \end{cfa} 4029 4043 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4030 3456 @7@ 345@67@ 34@567@4031 3456 @.@ 345@6.@ 34@56.@4032 abcd @e@ abc@de@ ab@cde@4033 \end{cfa} 4034 4035 For integer types, ©precision©is the minimum number of printed digits.4044 3456®7® 345®67® 34®567® 4045 3456®.® 345®6.® 34®56.® 4046 abcd®e® abc®de® ab®cde® 4047 \end{cfa} 4048 4049 For integer types, precision is the minimum number of printed digits. 4036 4050 If the value is shorter, it is padded on the left with leading zeros. 4037 4051 \begin{cfa}[belowskip=0pt] … … 4039 4053 \end{cfa} 4040 4054 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4041 @0@34 @00@34 @00000000@344042 \end{cfa} 4043 If the value is larger, it is printed without truncation, ignoring the ©precision©.4055 ®0®34 ®00®34 ®00000000®34 4056 \end{cfa} 4057 If the value is larger, it is printed without truncation, ignoring the precision. 4044 4058 \begin{cfa}[belowskip=0pt] 4045 4059 sout  wd( 4,1, 3456 )  wd( 8,2, 3456 )  wd( 10,3, 3456 ); … … 4048 4062 3456 3456 3456 4049 4063 \end{cfa} 4050 If ©precision©is 0, nothing is printed for zero.4051 If ©precision©is greater than the minimum, it becomes the minimum.4064 If precision is 0, nothing is printed for zero. 4065 If precision is greater than the minimum, it becomes the minimum. 4052 4066 \begin{cfa}[belowskip=0pt] 4053 4067 sout  wd( 4,0, 0 )  wd( 3,10, 34 ); 4054 4068 \end{cfa} 4055 4069 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4056 @ @ @00000000@344057 \end{cfa} 4058 For floatingpoint types, ©precision©is the minimum number of digits after the decimal point.4070 ® ® ®00000000®34 4071 \end{cfa} 4072 For floatingpoint types, precision is the minimum number of digits after the decimal point. 4059 4073 \begin{cfa}[belowskip=0pt] 4060 4074 sout  wd( 6,3, 27.5 )  wd( 8,1, 27.5 )  wd( 8,0, 27.5 )  wd( 3,8, 27.5 ); 4061 4075 \end{cfa} 4062 4076 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4063 27. @500@ 27.@5@ 28. 27.@50000000@4064 \end{cfa} 4065 For the Cstring type, ©precision©is the maximum number of printed characters, so the string is truncated if it exceeds the maximum.4077 27.®500® 27.®5® 28. 27.®50000000® 4078 \end{cfa} 4079 For the Cstring type, precision is the maximum number of printed characters, so the string is truncated if it exceeds the maximum. 4066 4080 \begin{cfa}[belowskip=0pt] 4067 4081 sout  wd( 6,8, "abcd" )  wd( 6,8, "abcdefghijk" )  wd( 6,3, "abcd" ); … … 4072 4086 4073 4087 \item 4074 \Indexc{ws( unsigned char minimum, unsigned char significant, floatingpoint )}\index{manipulator!ws@©ws©} 4075 For floatingpoint type, ©minimum© is the same as for manipulator ©wd©, but ©significant© is the maximum number of significant digits to be printed for both the integer and fractions (versus only the fraction for ©wd©). 4076 If a value's significant digits is greater than ©significant©, the last significant digit is rounded up. 4088 \begin{sloppypar} 4089 \Indexc{ws}( minimum, significant, floatingpoint )\index{manipulator!ws@©ws©} 4090 For floatingpoint types, minimum is the same as for manipulator ©wd©, but significant is the maximum number of significant digits to be printed for both the integer and fractions (versus only the fraction for ©wd©). 4091 If a value's significant digits is greater than significant, the last significant digit is rounded up. 4092 \end{sloppypar} 4077 4093 \begin{cfa}[belowskip=0pt] 4078 4094 sout  ws(6,6, 234.567)  ws(6,5, 234.567)  ws(6,4, 234.567)  ws(6,3, 234.567); 4079 4095 \end{cfa} 4080 4096 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4081 234.567 234.5 @7@ 234.@6@ 23@5@4082 \end{cfa} 4083 If a value's magnitude is greater than ©significant©, the value is printed in scientific notation with the specified number of significant digits.4097 234.567 234.5®7® 234.®6® 23®5® 4098 \end{cfa} 4099 If a value's magnitude is greater than significant, the value is printed in scientific notation with the specified number of significant digits. 4084 4100 \begin{cfa}[belowskip=0pt] 4085 4101 sout  ws(6,6, 234567.)  ws(6,5, 234567.)  ws(6,4, 234567.)  ws(6,3, 234567.); 4086 4102 \end{cfa} 4087 4103 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4088 234567. 2.3457 @e+05@ 2.346@e+05@ 2.35@e+05@4089 \end{cfa} 4090 If ©significant© is greater than ©minimum©, it defines the number of printed characters.4104 234567. 2.3457®e+05® 2.346®e+05® 2.35®e+05® 4105 \end{cfa} 4106 If significant is greater than minimum, it defines the number of printed characters. 4091 4107 \begin{cfa}[belowskip=0pt] 4092 4108 sout  ws(3,6, 234567.)  ws(4,6, 234567.)  ws(5,6, 234567.)  ws(6,6, 234567.); … … 4102 4118 \end{cfa} 4103 4119 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4104 27 @ @ 27.000000 27.500000 027 27.500@ @4120 27® ® 27.000000 27.500000 027 27.500® ® 4105 4121 \end{cfa} 4106 4122 … … 4109 4125 \begin{cfa}[belowskip=0pt] 4110 4126 sout  pad0( wd( 4, 27 ) )  pad0( wd( 4,3, 27 ) )  pad0( wd( 8,3, 27.5 ) ); 4111 @00@27 @0@27 @00@27.5004127 ®00®27 ®0®27 ®00®27.500 4112 4128 \end{cfa} 4113 4129 \end{enumerate} … … 4194 4210 \begin{enumerate} 4195 4211 \item 4196 \Indexc{skip( const char * pattern )}\index{manipulator!skip@©skip©} / ©skip( unsigned int length )© / ©const char * pattern© 4197 The argument defines a ©pattern© or ©length©. 4198 The ©pattern© is composed of whitespace and nonwhitespace characters, where \emph{any} whitespace character matches 0 or more input whitespace characters (hence, consecutive whitespace characters in the pattern are combined), and each nonwhitespace character matches exactly with an input character. 4199 The ©length© is composed of the next $N$ characters, including the newline character. 4212 \Indexc{skip}( pattern )\index{manipulator!skip@©skip©}, ©skip©( length ) 4213 The pattern is composed of whitespace and nonwhitespace characters, where \emph{any} whitespace character matches 0 or more input whitespace characters (hence, consecutive whitespace characters in the pattern are combined), and each nonwhitespace character matches exactly with an input character. 4214 The length is composed of the next $N$ characters, including the newline character. 4200 4215 If the match successes, the input characters are discarded, and input continues with the next character. 4201 4216 If the match fails, the input characters are left unread. … … 4205 4220 \end{cfa} 4206 4221 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4207 @abc @ 4208 @abc @ 4209 @xx@ 4210 \end{cfa} 4211 4212 \item 4213 \Indexc{wdi} ©( unsigned int maximum, T & val )©\index{manipulator!wdi@©wdi©}4214 For all types except ©char©, ©maximum©is the maximum number of characters read for the current operation.4222 ®abc ® 4223 ®abc ® 4224 ®xx® 4225 \end{cfa} 4226 4227 \item 4228 \Indexc{wdi}( maximum, referencevalue )\index{manipulator!wdi@©wdi©} 4229 For all types except ©char©, maximum is the maximum number of characters read for the current operation. 4215 4230 \begin{cfa}[belowskip=0pt] 4216 4231 char s[10]; int i; double d; … … 4218 4233 \end{cfa} 4219 4234 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4220 @abcd1233.456E+2@ 4235 ®abcd1233.456E+2® 4221 4236 \end{cfa} 4222 4237 Note, input ©wdi© cannot be overloaded with output ©wd© because both have the same parameters but return different types. … … 4224 4239 4225 4240 \item 4226 \Indexc{ignore ( T & val )}\index{manipulator!ignore@©ignore©}4241 \Indexc{ignore}( referencevalue )\index{manipulator!ignore@©ignore©} 4227 4242 For all types, the data is read from the stream depending on the argument type but ignored, \ie it is not stored in the argument. 4228 4243 \begin{cfa}[belowskip=0pt] … … 4231 4246 \end{cfa} 4232 4247 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4233 @ 75.35e4@254234 \end{cfa} 4235 4236 \item 4237 \Indexc{incl ( const char * scanset, char * s )}\index{manipulator!incl@©incl©}4238 For the Cstring type, the argument defines a ©scanset© that matches any number of characters \emph{in} the set.4239 Matching characters are read into the C string and null terminated.4248 ® 75.35e4® 25 4249 \end{cfa} 4250 4251 \item 4252 \Indexc{incl}( scanset, inputstring )\index{manipulator!incl@©incl©} 4253 For Cstring types, the scanset matches any number of characters \emph{in} the set. 4254 Matching characters are read into the C inputstring and null terminated. 4240 4255 \begin{cfa}[belowskip=0pt] 4241 4256 char s[10]; … … 4243 4258 \end{cfa} 4244 4259 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4245 @bca@xyz4246 \end{cfa} 4247 4248 \item 4249 \Indexc{excl ( const char * scanset, char * s )}\index{manipulator!excl@©excl©}4250 For the Cstring type, the argument defines a ©scanset© that matches any number of characters \emph{not in} the set.4251 Nonmatching characters are read into the C string and null terminated.4260 ®bca®xyz 4261 \end{cfa} 4262 4263 \item 4264 \Indexc{excl}( scanset, inputstring )\index{manipulator!excl@©excl©} 4265 For Cstring types, the scanset matches any number of characters \emph{not in} the set. 4266 Nonmatching characters are read into the C inputstring and null terminated. 4252 4267 \begin{cfa}[belowskip=0pt] 4253 4268 char s[10]; … … 4255 4270 \end{cfa} 4256 4271 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4257 @xyz@bca4272 ®xyz®bca 4258 4273 \end{cfa} 4259 4274 \end{enumerate} … … 4306 4321 The common usage is manipulator ©acquire©\index{ostream@©ostream©!acquire@©acquire©} to lock a stream during a single cascaded I/O expression, with the manipulator appearing as the first item in a cascade list, \eg: 4307 4322 \begin{cfa} 4308 $\emph{thread\(_1\)}$ : sout  @acquire@ "abc "  "def "; // manipulator4309 $\emph{thread\(_2\)}$ : sout  @acquire@ "uvw "  "xyz ";4323 $\emph{thread\(_1\)}$ : sout  ®acquire®  "abc "  "def "; // manipulator 4324 $\emph{thread\(_2\)}$ : sout  ®acquire®  "uvw "  "xyz "; 4310 4325 \end{cfa} 4311 4326 Now, the order of the thread execution is still nondeterministic, but the output is constrained to two possible lines in either order. … … 4329 4344 \begin{cfa} 4330 4345 { // acquire sout for block duration 4331 @osacquire@acq = { sout }; $\C{// named stream locker}$4346 ®osacquire® acq = { sout }; $\C{// named stream locker}$ 4332 4347 sout  1; 4333 sout  @acquire@ 2  3; $\C{// unnecessary, but ok to acquire and release again}$4348 sout  ®acquire®  2  3; $\C{// unnecessary, but ok to acquire and release again}$ 4334 4349 sout  4; 4335 4350 } // implicitly release the lock when "acq" is deallocated … … 4341 4356 \begin{cfa} 4342 4357 { // acquire sin lock for block duration 4343 @isacquire acq = { sin };@$\C{// named stream locker}$4358 ®isacquire acq = { sin };® $\C{// named stream locker}$ 4344 4359 int x, y, z, w; 4345 4360 sin  x; 4346 sin  @acquire@ y  z; $\C{// unnecessary, but ok to acquire and release again}$4361 sin  ®acquire®  y  z; $\C{// unnecessary, but ok to acquire and release again}$ 4347 4362 sin  w; 4348 4363 } // implicitly release the lock when "acq" is deallocated … … 4353 4368 \Textbf{WARNING:} The general problem of \Index{nested locking} can occur if routines are called in an I/O sequence that block, \eg: 4354 4369 \begin{cfa} 4355 sout  @acquire@ "data:"  rtn( mon ); $\C{// mutex call on monitor}$4370 sout  ®acquire®  "data:"  rtn( mon ); $\C{// mutex call on monitor}$ 4356 4371 \end{cfa} 4357 4372 If the thread executing the I/O expression blocks in the monitor with the ©sout© lock, other threads writing to ©sout© also block until the thread holding the lock is unblocked and releases it. … … 4359 4374 To prevent nested locking, a simple precaution is to factor out the blocking call from the expression, \eg: 4360 4375 \begin{cfa} 4361 int @data@= rtn( mon );4362 sout  acquire  "data:"  @data@;4376 int ®data® = rtn( mon ); 4377 sout  acquire  "data:"  ®data®; 4363 4378 \end{cfa} 4364 4379 … … 4809 4824 For example, given 4810 4825 \begin{cfa} 4811 auto j = @...@4826 auto j = ®...® 4812 4827 \end{cfa} 4813 4828 and the need to write a routine to compute using ©j© 4814 4829 \begin{cfa} 4815 void rtn( @...@parm );4830 void rtn( ®...® parm ); 4816 4831 rtn( j ); 4817 4832 \end{cfa} … … 5051 5066 \begin{cfa} 5052 5067 #include <fstream.hfa> 5053 #include @<coroutine.hfa>@5054 5055 @coroutine@Fibonacci {5068 #include ®<coroutine.hfa>® 5069 5070 ®coroutine® Fibonacci { 5056 5071 int fn; $\C{// used for communication}$ 5057 5072 }; … … 5060 5075 int fn1, fn2; $\C{// retained between resumes}$ 5061 5076 fn = 0; fn1 = fn; $\C{// 1st case}$ 5062 @suspend;@$\C{// restart last resume}$5077 ®suspend;® $\C{// restart last resume}$ 5063 5078 fn = 1; fn2 = fn1; fn1 = fn; $\C{// 2nd case}$ 5064 @suspend;@$\C{// restart last resume}$5079 ®suspend;® $\C{// restart last resume}$ 5065 5080 for () { 5066 5081 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; $\C{// general case}$ 5067 @suspend;@$\C{// restart last resume}$5082 ®suspend;® $\C{// restart last resume}$ 5068 5083 } 5069 5084 } 5070 5085 int next( Fibonacci & fib ) with( fib ) { 5071 @resume( fib );@$\C{// restart last suspend}$5086 ®resume( fib );® $\C{// restart last suspend}$ 5072 5087 return fn; 5073 5088 } … … 5106 5121 \begin{cfa} 5107 5122 #include <fstream.hfa> 5108 #include @<thread.hfa>@5109 5110 @monitor@AtomicCnt { int counter; };5123 #include ®<thread.hfa>® 5124 5125 ®monitor® AtomicCnt { int counter; }; 5111 5126 void ?{}( AtomicCnt & c, int init = 0 ) with(c) { counter = init; } 5112 int inc( AtomicCnt & @mutex@c, int inc = 1 ) with(c) { return counter += inc; }5113 int dec( AtomicCnt & @mutex@c, int dec = 1 ) with(c) { return counter = dec; }5127 int inc( AtomicCnt & ®mutex® c, int inc = 1 ) with(c) { return counter += inc; } 5128 int dec( AtomicCnt & ®mutex® c, int dec = 1 ) with(c) { return counter = dec; } 5114 5129 forall( ostype &  ostream( ostype ) ) { $\C{// print any stream}$ 5115 5130 ostype & ??( ostype & os, AtomicCnt c ) { return os  c.counter; } … … 6599 6614 6600 6615 C has a number of syntax ambiguities, which are resolved by taking the longest sequence of overlapping characters that constitute a token. 6601 For example, the program fragment ©x+++++y© is parsed as \lstinline[showspaces=true] @x ++ ++ + y@because operator tokens ©++© and ©+© overlap.6602 Unfortunately, the longest sequence violates a constraint on increment operators, even though the parse \lstinline[showspaces=true] @x ++ + ++ y@might yield a correct expression.6616 For example, the program fragment ©x+++++y© is parsed as \lstinline[showspaces=true]{x ++ ++ + y} because operator tokens ©++© and ©+© overlap. 6617 Unfortunately, the longest sequence violates a constraint on increment operators, even though the parse \lstinline[showspaces=true]{x ++ + ++ y} might yield a correct expression. 6603 6618 Hence, C programmers are aware that spaces have to added to disambiguate certain syntactic cases. 6604 6619 … … 6620 6635 requiring arbitrary whitespace lookahead for the routinecall parameterlist to disambiguate. 6621 6636 However, the dereference operator \emph{must} have a parameter/argument to dereference ©*?(...)©. 6622 Hence, always interpreting the string ©*?()© as \lstinline[showspaces=true] @* ?()@does not preclude any meaningful program.6637 Hence, always interpreting the string ©*?()© as \lstinline[showspaces=true]{* ?()} does not preclude any meaningful program. 6623 6638 6624 6639 The remaining cases are with the increment/decrement operators and conditional expression, \eg: … … 6728 6743 \begin{cfa} 6729 6744 int i; $\C{// forward definition}$ 6730 int *j = @&i@; $\C{// forward reference, valid in C, invalid in \CFA}$6745 int *j = ®&i®; $\C{// forward reference, valid in C, invalid in \CFA}$ 6731 6746 int i = 0; $\C{// definition}$ 6732 6747 \end{cfa} … … 6736 6751 struct X { int i; struct X *next; }; 6737 6752 static struct X a; $\C{// forward definition}$ 6738 static struct X b = { 0, @&a@};$\C{// forward reference, valid in C, invalid in \CFA}$6753 static struct X b = { 0, ®&a® };$\C{// forward reference, valid in C, invalid in \CFA}$ 6739 6754 static struct X a = { 1, &b }; $\C{// definition}$ 6740 6755 \end{cfa} … … 6749 6764 \item[Change:] have ©struct© introduce a scope for nested types: 6750 6765 \begin{cfa} 6751 enum @Colour@{ R, G, B, Y, C, M };6766 enum ®Colour® { R, G, B, Y, C, M }; 6752 6767 struct Person { 6753 enum @Colour@{ R, G, B }; $\C[7cm]{// nested type}$6768 enum ®Colour® { R, G, B }; $\C[7cm]{// nested type}$ 6754 6769 struct Face { $\C{// nested type}$ 6755 @Colour@Eyes, Hair; $\C{// type defined outside (1 level)}$6770 ®Colour® Eyes, Hair; $\C{// type defined outside (1 level)}$ 6756 6771 }; 6757 @.Colour@shirt; $\C{// type defined outside (top level)}$6758 @Colour@pants; $\C{// type defined same level}$6772 ®.Colour® shirt; $\C{// type defined outside (top level)}$ 6773 ®Colour® pants; $\C{// type defined same level}$ 6759 6774 Face looks[10]; $\C{// type defined same level}$ 6760 6775 }; 6761 @Colour@c = R; $\C{// type/enum defined same level}$6762 Person @.Colour@ pc = Person@.@R;$\C{// type/enum defined inside}$6763 Person @.@Face pretty; $\C{// type defined inside}\CRT$6776 ®Colour® c = R; $\C{// type/enum defined same level}$ 6777 Person®.Colour® pc = Person®.®R;$\C{// type/enum defined inside}$ 6778 Person®.®Face pretty; $\C{// type defined inside}\CRT$ 6764 6779 \end{cfa} 6765 6780 In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing structure, \ie the nested types are hoisted to the scope of the outermost type, which is not useful and confusing. … … 7064 7079 // assume ?? operator for printing an S 7065 7080 7066 S & sp = * @new@( 3 ); $\C{// call constructor after allocation}$7081 S & sp = *®new®( 3 ); $\C{// call constructor after allocation}$ 7067 7082 sout  sp.i; 7068 @delete@( &sp );7069 7070 S * spa = @anew@( 10, 5 ); $\C{// allocate array and initialize each array element}$7083 ®delete®( &sp ); 7084 7085 S * spa = ®anew®( 10, 5 ); $\C{// allocate array and initialize each array element}$ 7071 7086 for ( i; 10 ) sout  spa[i]  nonl; 7072 7087 sout  nl; 7073 @adelete@( 10, spa );7088 ®adelete®( 10, spa ); 7074 7089 \end{cfa} 7075 7090 Allocation routines ©new©/©anew© allocate a variable/array and initialize storage using the allocated type's constructor. … … 7683 7698 7684 7699 7685 %\subsection{\texorpdfstring{\protect\lstinline @Duration@}{Duration}}7700 %\subsection{\texorpdfstring{\protect\lstinline{Duration}}{Duration}} 7686 7701 \subsection{\texorpdfstring{\LstBasicStyle{Duration}}{Duration}} 7687 7702 \label{s:Duration} … … 7777 7792 7778 7793 7779 %\subsection{\texorpdfstring{\protect\lstinline @\timeval@}{timeval}}7794 %\subsection{\texorpdfstring{\protect\lstinline{timeval}}{timeval}} 7780 7795 \subsection{\texorpdfstring{\LstBasicStyle{timeval}}{timeval}} 7781 7796 \label{s:timeval} … … 7797 7812 7798 7813 7799 %\subsection{\texorpdfstring{\protect\lstinline @timespec@}{timespec}}7814 %\subsection{\texorpdfstring{\protect\lstinline{timespec}}{timespec}} 7800 7815 \subsection{\texorpdfstring{\LstBasicStyle{timespec}}{timespec}} 7801 7816 \label{s:timespec} … … 7817 7832 7818 7833 7819 %\subsection{\texorpdfstring{\protect\lstinline @itimerval@}{itimerval}}7834 %\subsection{\texorpdfstring{\protect\lstinline{itimerval}}{itimerval}} 7820 7835 \subsection{\texorpdfstring{\LstBasicStyle{itimerval}}{itimerval}} 7821 7836 \label{s:itimerval} … … 7828 7843 7829 7844 7830 %\subsection{\texorpdfstring{\protect\lstinline @Time@}{Time}}7845 %\subsection{\texorpdfstring{\protect\lstinline{Time}}{Time}} 7831 7846 \subsection{\texorpdfstring{\LstBasicStyle{Time}}{Time}} 7832 7847 \label{s:Time} … … 7894 7909 7895 7910 7896 %\subsection{\texorpdfstring{\protect\lstinline @Clock@}{Clock}}7911 %\subsection{\texorpdfstring{\protect\lstinline{Clock}}{Clock}} 7897 7912 \subsection{\texorpdfstring{\LstBasicStyle{Clock}}{Clock}} 7898 7913 \label{s:Clock} … … 8115 8130 #include <gmp.h>$\indexc{gmp.h}$ 8116 8131 int main( void ) { 8117 @gmp_printf@( "Factorial Numbers\n" );8118 @mpz_t@fact;8119 @mpz_init_set_ui@( fact, 1 );8120 @gmp_printf@( "%d %Zd\n", 0, fact );8132 ®gmp_printf®( "Factorial Numbers\n" ); 8133 ®mpz_t® fact; 8134 ®mpz_init_set_ui®( fact, 1 ); 8135 ®gmp_printf®( "%d %Zd\n", 0, fact ); 8121 8136 for ( unsigned int i = 1; i <= 40; i += 1 ) { 8122 @mpz_mul_ui@( fact, fact, i );8123 @gmp_printf@( "%d %Zd\n", i, fact );8137 ®mpz_mul_ui®( fact, fact, i ); 8138 ®gmp_printf®( "%d %Zd\n", i, fact ); 8124 8139 } 8125 8140 }
Note: See TracChangeset
for help on using the changeset viewer.