Changes in / [f9723e8:5a3d67c]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rf9723e8 r5a3d67c  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Mar  5 12:09:42 2020
    14 %% Update Count     : 3885
     13%% Last Modified On : Sat Jul 13 18:36:18 2019
     14%% Update Count     : 3876
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    211211Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    212212For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice.
    213 The TIOBE index~\cite{TIOBE} for February 2020 ranks the top six most \emph{popular} programming languages as \Index*{Java} 17.4\%, C 16.8\%, Python 9.3\%, \Index*[C++]{\CC{}} 6.2\%, \Csharp 5.9\%, Visual Basic 5.9\% = 61.5\%, where the next 50 languages are less than 2\% each, with a long tail.
    214 The top 4 rankings over the past 35 years are:
     213The TIOBE index~\cite{TIOBE} for July 2018 ranks the top five most \emph{popular} programming languages as \Index*{Java} 16\%, C 14\%, \Index*[C++]{\CC{}} 7.5\%, Python 6\%, Visual Basic 4\% = 47.5\%, where the next 50 languages are less than 4\% each, with a long tail.
     214The top 3 rankings over the past 30 years are:
    215215\begin{center}
    216216\setlength{\tabcolsep}{10pt}
    217 \begin{tabular}{@{}rcccccccc@{}}
    218                 & 2020  & 2015  & 2010  & 2005  & 2000  & 1995  & 1990  & 1985  \\ \hline
    219 Java    & 1             & 2             & 1             & 2             & 3             & -             & -             & -             \\
    220 \R{C}   & \R{2} & \R{1} & \R{2} & \R{1} & \R{1} & \R{2} & \R{1} & \R{1} \\
    221 Python  & 3             & 7             & 6             & 6             & 22    & 21    & -             & -             \\
    222 \CC             & 4             & 4             & 4             & 3             & 2             & 1             & 2             & 12    \\
     217\begin{tabular}{@{}rccccccc@{}}
     218                & 2018  & 2013  & 2008  & 2003  & 1998  & 1993  & 1988  \\ \hline
     219Java    & 1             & 2             & 1             & 1             & 16    & -             & -             \\
     220\R{C}   & \R{2} & \R{1} & \R{2} & \R{2} & \R{1} & \R{1} & \R{1} \\
     221\CC             & 3             & 4             & 3             & 3             & 2             & 2             & 5             \\
    223222\end{tabular}
    224223\end{center}
     
    513512Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    514513\begin{cfa}
    515 int ®``®otype = 3; §\C{// make keyword an identifier}§
    516 double ®``®forall = 3.5;
     514int ®`®otype®`® = 3; §\C{// make keyword an identifier}§
     515double ®`®forall®`® = 3.5;
    517516\end{cfa}
    518517
     
    525524// include file uses the CFA keyword "with".
    526525#if ! defined( with ) §\C{// nesting ?}§
    527 #define with ®``®with §\C{// make keyword an identifier}§
     526#define with ®`®with®`® §\C{// make keyword an identifier}§
    528527#define __CFA_BFD_H__
    529528#endif
    530 §{\color{red}\#\textbf{include\_next} <bfdlink.h>}§ §\C{// must have internal check for multiple expansion}§
     529
     530®#include_next <bfdlink.h> §\C{// must have internal check for multiple expansion}§
     531®
    531532#if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§
    532533#undef with
     
    575576\section{Exponentiation Operator}
    576577
    577 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(x,y)}, to perform the exponentiation operation.
    578 \CFA extends the basic operators with the exponentiation operator ©?®\®?©\index{?\\?@©?®\®?©} and ©?\=?©\index{?\\=?@©®\®=?©}, as in, ©x ®\® y© and ©x ®\®= y©, which means $x^y$ and $x \leftarrow x^y$.
     578C, \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.
     579\CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@©?\?©} and ©?\=?©\index{?\\=?@©\=?©}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
    579580The 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)©.
    580581
    581 There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
     582As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
    582583Integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication\footnote{The multiplication computation is $O(\log y)$.} (or shifting if the exponent is 2).
    583 Overflow for a large exponent or negative exponent returns zero.
     584Overflow from large exponents or negative exponents return zero.
    584585Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
    585586\begin{cfa}
     
    5885891 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
    589590\end{cfa}
    590 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.
     591Note, ©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.
    591592Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
    592593The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
     
    597598OT ?®\®?( OT ep, unsigned long int y );
    598599\end{cfa}
    599 The user type ©T© must define multiplication, one (©1©), and ©*©.
     600The user type ©T© must define multiplication, one, ©1©, and, ©*©.
    600601
    601602
     
    625626
    626627
    627 %\section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}}
    628 \subsection{\texorpdfstring{\LstKeywordStyle{case} Clause}{case Clause}}
    629 
    630 C restricts the ©case© clause of a ©switch© statement to a single value.
    631 For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values.
    632 Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C.
    633 Therefore, the ©case© clause is extended with a list of values, as in:
     628\subsection{Loop Control}
     629
     630The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
     631\begin{itemize}
     632\item
     633An empty conditional implies ©1©.
     634\item
     635The up-to range ©~©\index{~@©~©} means exclusive range [M,N).
     636\item
     637The up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
     638\item
     639The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M).
     640\item
     641The down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M].
     642\item
     643©@© means put nothing in this field.
     644\item
     645©0© is the implicit start value;
     646\item
     647©1© is the implicit increment value.
     648\item
     649The up-to range uses ©+=© for increment;
     650\item
     651The down-to range uses ©-=© for decrement.
     652\item
     653The loop index is polymorphic in the type of the start value or comparison value when start is implicitly ©0©.
     654\end{itemize}
     655
     656\begin{figure}
    634657\begin{cquote}
    635 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    636 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
    637 \begin{cfa}
    638 switch ( i ) {
    639   case ®1, 3, 5®:
    640         ...
    641   case ®2, 4, 6®:
    642         ...
    643 }
     658\begin{tabular}{@{}l|l@{}}
     659\multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
     660\hline
     661\begin{cfa}
     662sout | nlOff;
     663while ®()® { sout | "empty"; break; } sout | nl;
     664do { sout | "empty"; break; } while ®()®; sout | nl;
     665for ®()® { sout | "empty"; break; } sout | nl;
     666for ( ®0® ) { sout | "A"; } sout | "zero" | nl;
     667for ( ®1® ) { sout | "A"; } sout | nl;
     668for ( ®10® ) { sout | "A"; } sout | nl;
     669for ( ®1 ~= 10 ~ 2® ) { sout | "B"; } sout | nl;
     670for ( ®10 -~= 1 ~ 2® ) { sout | "C"; } sout | nl;
     671for ( ®0.5 ~ 5.5® ) { sout | "D"; } sout | nl;
     672for ( ®5.5 -~ 0.5® ) { sout | "E"; } sout | nl;
     673for ( ®i; 10® ) { sout | i; } sout | nl;
     674for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; } sout | nl;
     675for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; } sout | nl;
     676for ( ®i; 0.5 ~ 5.5® ) { sout | i; } sout | nl;
     677for ( ®i; 5.5 -~ 0.5® ) { sout | i; } sout | nl;
     678for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; } sout | nl;
     679for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; } sout | nl;
     680enum { N = 10 };
     681for ( ®N® ) { sout | "N"; } sout | nl;
     682for ( ®i; N® ) { sout | i; } sout | nl;
     683for ( ®i; N -~ 0® ) { sout | i; } sout | nl;
     684const int start = 3, comp = 10, inc = 2;
     685for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; } sout | nl;
     686for ( ®i; 1 ~ @® ) { if ( i > 10 ) break;
     687        sout | i; } sout | nl;
     688for ( ®i; 10 -~ @® ) { if ( i < 0 ) break;
     689        sout | i; } sout | nl;
     690for ( ®i; 2 ~ @ ~ 2® ) { if ( i > 10 ) break;
     691        sout | i; } sout | nl;
     692for ( ®i; 2.1 ~ @ ~ @® ) { if ( i > 10.5 ) break;
     693        sout | i; i += 1.7; } sout | nl;
     694for ( ®i; 10 -~ @ ~ 2® ) { if ( i < 0 ) break;
     695        sout | i; } sout | nl;
     696for ( ®i; 12.1 ~ @ ~ @® ) { if ( i < 2.5 ) break;
     697        sout | i; i -= 1.7; } sout | nl;
     698for ( ®i; 5 : j; -5 ~ @® ) { sout | i | j; } sout | nl;
     699for ( ®i; 5 : j; -5 -~ @® ) { sout | i | j; } sout | nl;
     700for ( ®i; 5 : j; -5 ~ @ ~ 2® ) { sout | i | j; } sout | nl;
     701for ( ®i; 5 : j; -5 -~ @ ~ 2® ) { sout | i | j; } sout | nl;
     702for ( ®j; -5 ~ @ : i; 5® ) { sout | i | j; } sout | nl;
     703for ( ®j; -5 -~ @ : i; 5® ) { sout | i | j; } sout | nl;
     704for ( ®j; -5 ~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
     705for ( ®j; -5 -~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
     706for ( ®j; -5 -~ @ ~ 2 : i; 5 : k; 1.5 ~ @® ) {
     707        sout | i | j | k; } sout | nl;
     708for ( ®j; -5 -~ @ ~ 2 : k; 1.5 ~ @ : i; 5® ) {
     709        sout | i | j | k; } sout | nl;
     710for ( ®k; 1.5 ~ @ : j; -5 -~ @ ~ 2 : i; 5® ) {
     711        sout | i | j | k; } sout | nl;
    644712\end{cfa}
    645713&
    646714\begin{cfa}
    647 switch ( i ) {
    648   case 1: case 3 : case 5:
    649         ...
    650   case 2: case 4 : case 6:
    651         ...
    652 }
    653 \end{cfa}
    654 &
    655 \begin{cfa}
    656 
    657 // odd values
    658 
    659 // even values
    660 
    661 
     715
     716empty
     717empty
     718empty
     719zero
     720A
     721A A A A A A A A A A
     722B B B B B
     723C C C C C
     724D D D D D
     725E E E E E
     7260 1 2 3 4 5 6 7 8 9
     7271 3 5 7 9
     72810 8 6 4 2
     7290.5 1.5 2.5 3.5 4.5
     7305.5 4.5 3.5 2.5 1.5
     7312 4 6 8 10
     73210 8 6 4 2
     733
     734N N N N N N N N N N
     7350 1 2 3 4 5 6 7 8 9
     73610 9 8 7 6 5 4 3 2 1
     737
     7383 6 9
     739
     7401 2 3 4 5 6 7 8 9 10
     741
     74210 9 8 7 6 5 4 3 2 1 0
     743
     7442 4 6 8 10
     745
     7462.1 3.8 5.5 7.2 8.9
     747
     74810 8 6 4 2 0
     749
     75012.1 10.4 8.7 7 5.3 3.6
     7510 -5 1 -4 2 -3 3 -2 4 -1
     7520 -5 1 -6 2 -7 3 -8 4 -9
     7530 -5 1 -3 2 -1 3 1 4 3
     7540 -5 1 -7 2 -9 3 -11 4 -13
     7550 -5 1 -4 2 -3 3 -2 4 -1
     7560 -5 1 -6 2 -7 3 -8 4 -9
     7570 -5 1 -3 2 -1 3 1 4 3
     7580 -5 1 -7 2 -9 3 -11 4 -13
     759
     7600 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     761
     7620 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     763
     7640 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    662765\end{cfa}
    663766\end{tabular}
    664767\end{cquote}
    665 In addition, subranges are allowed to specify case values.\footnote{
    666 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.}
    667 \begin{cfa}
    668 switch ( i ) {
    669   case ®1~5:® §\C{// 1, 2, 3, 4, 5}§
    670         ...
    671   case ®10~15:® §\C{// 10, 11, 12, 13, 14, 15}§
    672         ...
    673 }
    674 \end{cfa}
    675 Lists of subranges are also allowed.
    676 \begin{cfa}
    677 case ®1~5, 12~21, 35~42®:
    678 \end{cfa}
     768\caption{Loop Control Examples}
     769\label{f:LoopControlExamples}
     770\end{figure}
    679771
    680772
     
    885977
    886978
    887 \subsection{Non-terminating and Labelled \texorpdfstring{\LstKeywordStyle{fallthrough}}{Non-terminating and Labelled fallthrough}}
    888 
    889 The ©fallthrough© clause may be non-terminating within a ©case© clause or have a target label to common code from multiple case clauses.
    890 \begin{center}
    891 \begin{tabular}{@{}lll@{}}
    892 \begin{cfa}
    893 choose ( ... ) {
    894   case 3:
    895         if ( ... ) {
    896                 ... ®fallthru;® // goto case 4
    897         } else {
    898                 ...
    899         }
    900         // implicit break
    901   case 4:
    902 
    903 
    904 
    905 
     979%\section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}}
     980\subsection{\texorpdfstring{\LstKeywordStyle{case} Statement}{case Statement}}
     981
     982C restricts the ©case© clause of a ©switch© statement to a single value.
     983For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values.
     984Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C.
     985Therefore, the ©case© clause is extended with a list of values, as in:
     986\begin{cquote}
     987\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
     988\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     989\begin{cfa}
     990switch ( i ) {
     991  case ®1, 3, 5®:
     992        ...
     993  case ®2, 4, 6®:
     994        ...
     995}
    906996\end{cfa}
    907997&
    908998\begin{cfa}
    909 choose ( ... ) {
    910   case 3:
    911         ... ®fallthrough common;®
    912   case 4:
    913         ... ®fallthrough common;®
    914 
    915   ®common:® // below fallthrough
    916                           // at case-clause level
    917         ...     // common code for cases 3/4
    918         // implicit break
    919   case 4:
    920 
    921 
     999switch ( i ) {
     1000  case 1: case 3 : case 5:
     1001        ...
     1002  case 2: case 4 : case 6:
     1003        ...
     1004}
    9221005\end{cfa}
    9231006&
    9241007\begin{cfa}
    925 choose ( ... ) {
    926   case 3:
    927         choose ( ... ) {
    928           case 4:
    929                 for ( ... ) {
    930                         // multi-level transfer
    931                         ... ®fallthru common;®
    932                 }
    933                 ...
    934         }
     1008
     1009// odd values
     1010
     1011// even values
     1012
     1013
     1014\end{cfa}
     1015\end{tabular}
     1016\end{cquote}
     1017In addition, subranges are allowed to specify case values.\footnote{
     1018gcc 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.}
     1019\begin{cfa}
     1020switch ( i ) {
     1021  case ®1~5:® §\C{// 1, 2, 3, 4, 5}§
    9351022        ...
    936   ®common:® // below fallthrough
    937                           // at case-clause level
    938 \end{cfa}
    939 \end{tabular}
    940 \end{center}
    941 The target label must be below the ©fallthrough© and may not be nested in a control structure, and
    942 the target label must be at the same or higher level as the containing ©case© clause and located at
    943 the same level as a ©case© clause; the target label may be case ©default©, but only associated
    944 with the current ©switch©/©choose© statement.
    945 
    946 
    947 \subsection{Loop Control}
    948 
    949 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
    950 \begin{itemize}
    951 \item
    952 The loop index is polymorphic in the type of the comparison value N (when the start value is implicit) or the start value M.
    953 \item
    954 An empty conditional implies comparison value of ©1© (true).
    955 \item
    956 A comparison N is implicit up-to exclusive range [0,N©®)®©.
    957 \item
    958 A comparison ©=© N is implicit up-to inclusive range [0,N©®]®©.
    959 \item
    960 The up-to range M ©~©\index{~@©~©} N means exclusive range [M,N©®)®©.
    961 \item
    962 The up-to range M ©~=©\index{~=@©~=©} N means inclusive range [M,N©®]®©.
    963 \item
    964 The down-to range M ©-~©\index{-~@©-~©} N means exclusive range [N,M©®)®©.
    965 \item
    966 The down-to range M ©-~=©\index{-~=@©-~=©} N means inclusive range [N,M©®]®©.
    967 \item
    968 ©0© is the implicit start value;
    969 \item
    970 ©1© is the implicit increment value.
    971 \item
    972 The up-to range uses operator ©+=© for increment;
    973 \item
    974 The down-to range uses operator ©-=© for decrement.
    975 \item
    976 ©@© means put nothing in this field.
    977 \item
    978 ©:© means start another index.
    979 \end{itemize}
    980 
    981 \begin{figure}
    982 \begin{tabular}{@{}l|l@{}}
    983 \multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
    984 \hline
    985 \begin{cfa}[xleftmargin=0pt]
    986 while ®()® { sout | "empty"; break; }
    987 do { sout | "empty"; break; } while ®()®;
    988 for ®()® { sout | "empty"; break; }
    989 for ( ®0® ) { sout | "A"; } sout | "zero";
    990 for ( ®1® ) { sout | "A"; }
    991 for ( ®10® ) { sout | "A"; }
    992 for ( ®= 10® ) { sout | "A"; }
    993 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
    994 for ( ®10 -~= 1 ~ 2® ) { sout | "C"; }
    995 for ( ®0.5 ~ 5.5® ) { sout | "D"; }
    996 for ( ®5.5 -~ 0.5® ) { sout | "E"; }
    997 for ( ®i; 10® ) { sout | i; }
    998 for ( ®i; = 10® ) { sout | i; }
    999 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
    1000 for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; }
    1001 for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
    1002 for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
    1003 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
    1004 for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; }
    1005 enum { N = 10 };
    1006 for ( ®N® ) { sout | "N"; }
    1007 for ( ®i; N® ) { sout | i; }
    1008 for ( ®i; N -~ 0® ) { sout | i; }
    1009 const int start = 3, comp = 10, inc = 2;
    1010 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
    1011 for ( i; 1 ~ ®@® ) { if ( i > 10 ) break; sout | i; }
    1012 for ( i; 10 -~ ®@® ) { if ( i < 0 ) break; sout | i; }
    1013 for ( i; 2 ~ ®@® ~ 2 ) { if ( i > 10 ) break; sout | i; }
    1014 for ( i; 2.1 ~ ®@® ~ ®@® ) { if ( i > 10.5 ) break; sout | i; i += 1.7; }
    1015 for ( i; 10 -~ ®@® ~ 2 ) { if ( i < 0 ) break; sout | i; }
    1016 for ( i; 12.1 ~ ®@® ~ ®@® ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; }
    1017 for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
    1018 for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
    1019 for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
    1020 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
    1021 for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
    1022 for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
    1023 for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
    1024 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
    1025 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
    1026 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
    1027 for ( i; 5 ®:® k; 1.5 ~ @ ®:® j; -5 -~ @ ~ 2 ) { sout | i | j | k; }
    1028 \end{cfa}
    1029 &
    1030 \begin{cfa}
    1031 empty
    1032 empty
    1033 empty
    1034 zero
    1035 A
    1036 A A A A A A A A A A
    1037 A A A A A A A A A A A
    1038 B B B B B
    1039 C C C C C
    1040 D D D D D
    1041 E E E E E
    1042 0 1 2 3 4 5 6 7 8 9
    1043 0 1 2 3 4 5 6 7 8 9 10
    1044 1 3 5 7 9
    1045 10 8 6 4 2
    1046 0.5 1.5 2.5 3.5 4.5
    1047 5.5 4.5 3.5 2.5 1.5
    1048 2 4 6 8 10
    1049 10 8 6 4 2
    1050 
    1051 N N N N N N N N N N
    1052 0 1 2 3 4 5 6 7 8 9
    1053 10 9 8 7 6 5 4 3 2 1
    1054 
    1055 3 6 9
    1056 1 2 3 4 5 6 7 8 9 10
    1057 10 9 8 7 6 5 4 3 2 1 0
    1058 2 4 6 8 10
    1059 2.1 3.8 5.5 7.2 8.9
    1060 10 8 6 4 2 0
    1061 12.1 10.4 8.7 7. 5.3 3.6
    1062 0 -5 1 -4 2 -3 3 -2 4 -1
    1063 0 -5 1 -6 2 -7 3 -8 4 -9
    1064 0 -5 1 -3 2 -1 3 1 4 3
    1065 0 -5 1 -7 2 -9 3 -11 4 -13
    1066 0 -5 1 -4 2 -3 3 -2 4 -1
    1067 0 -5 1 -6 2 -7 3 -8 4 -9
    1068 0 -5 1 -3 2 -1 3 1 4 3
    1069 0 -5 1 -7 2 -9 3 -11 4 -13
    1070 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    1071 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    1072 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    1073 \end{cfa}
    1074 \end{tabular}
    1075 \caption{Loop Control Examples}
    1076 \label{f:LoopControlExamples}
    1077 \end{figure}
     1023  case ®10~15:® §\C{// 10, 11, 12, 13, 14, 15}§
     1024        ...
     1025}
     1026\end{cfa}
     1027Lists of subranges are also allowed.
     1028\begin{cfa}
     1029case ®1~5, 12~21, 35~42®:
     1030\end{cfa}
     1031
    10781032
    10791033% for ()  => for ( ;; )
     
    65936547hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}).
    65946548All other C header files must be explicitly wrapped in ©extern "C"© to prevent name mangling.
    6595 This approach is different from \Index*[C++]{\CC{}} where the name-mangling issue is handled internally in C header-files through checks for preprocessor variable ©__cplusplus©, which adds appropriate ©extern "C"© qualifiers.
     6549For \Index*[C++]{\CC{}}, the name-mangling issue is often handled internally in many C header-files through checks for preprocessor variable ©__cplusplus©, which adds appropriate ©extern "C"© qualifiers.
    65966550
    65976551
     
    66076561The storage-management routines extend their C equivalents by overloading, alternate names, providing shallow type-safety, and removing the need to specify the allocation size for non-array types.
    66086562
    6609 C storage management provides the following capabilities:
     6563Storage management provides the following capabilities:
    66106564\begin{description}
    6611 \item[filled]
    6612 after allocation with a specified character or value.
     6565\item[fill]
     6566after allocation the storage is filled with a specified character.
    66136567\item[resize]
    6614 an existing allocation to decreased or increased its size.
    6615 In either case, new storage may or may not be allocated and, if there is a new allocation, as much data from the existing allocation is copied into the new allocation.
     6568an existing allocation is decreased or increased in size.
     6569In either case, new storage may or may not be allocated and, if there is a new allocation, as much data from the existing allocation is copied.
    66166570For an increase in storage size, new storage after the copied data may be filled.
    6617 \item[align]
    6618 an allocation on a specified memory boundary, \eg, an address multiple of 64 or 128 for cache-line purposes.
     6571\item[alignment]
     6572an allocation starts on a specified memory boundary, \eg, an address multiple of 64 or 128 for cache-line purposes.
    66196573\item[array]
    66206574the allocation size is scaled to the specified number of array elements.
    66216575An array may be filled, resized, or aligned.
    66226576\end{description}
    6623 \VRef[Table]{t:AllocationVersusCapabilities} shows allocation routines supporting different combinations of storage-management capabilities:
    6624 \begin{table}
    6625 \centering
    6626 \begin{tabular}{@{}r|l|l|l|l|l@{}}
     6577The table shows allocation routines supporting different combinations of storage-management capabilities:
     6578\begin{center}
     6579\begin{tabular}{@{}r|r|l|l|l|l@{}}
    66276580\multicolumn{1}{c}{}&           & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
    66286581\hline
    66296582C               & ©malloc©                      & no                    & no            & no            & no    \\
    66306583                & ©calloc©                      & yes (0 only)  & no            & no            & yes   \\
    6631                 & ©realloc©                     & copy                  & yes           & no            & no    \\
     6584                & ©realloc©                     & no/copy               & yes           & no            & no    \\
    66326585                & ©memalign©            & no                    & no            & yes           & no    \\
    6633                 & ©aligned_alloc©       & no                    & no            & yes           & no    \\
    66346586                & ©posix_memalign©      & no                    & no            & yes           & no    \\
    66356587\hline
    6636 \CFA    & ©cmemalign©           & yes (0 only)  & no            & yes           & yes   \\
    6637                 & ©realloc©                     & copy                  & yes           & yes           & no    \\
    6638                 & ©alloc©                       & no                    & no            & no            & no    \\
    6639                 & ©alloc©                       & copy                  & no/yes        & no            & yes   \\
    6640                 & ©alloc©                       & no/copy/yes   & no/yes        & no            & yes   \\
    6641                 & ©alloc_set©           & no/yes                & no            & yes           & yes   \\
    6642                 & ©alloc_align©         & no/yes                & no            & yes           & yes   \\
    6643                 & ©alloc_align_set©     & no/yes                & no            & yes           & yes   \\
     6588C11             & ©aligned_alloc©       & no                    & no            & yes           & no    \\
     6589\hline
     6590\CFA    & ©alloc©                       & no/copy/yes   & no/yes        & no            & yes   \\
     6591                & ©align_alloc©         & no/yes                & no            & yes           & yes   \\
    66446592\end{tabular}
    6645 \caption{Allocation Routines versus Storage-Management Capabilities}
    6646 \label{t:AllocationVersusCapabilities}
    6647 \end{table}
    6648 
    6649 \CFA memory management extends the resize capability with the notion of \newterm{sticky properties}.
    6650 Hence, initial allocation capabilities are remembered and maintained when resize requires copying.
    6651 For example, an initial alignment and fill capability are preserved during a resize copy so the copy has the same alignment and extended storage is filled.
    6652 Without sticky properties it is dangerous to use ©realloc©, resulting in an idiom of manually performing the reallocation to maintain correctness.
    6653 
     6593\end{center}
     6594It is impossible to resize with alignment because the underlying ©realloc© allocates storage if more space is needed, and it does not honour alignment from the original allocation.
    66546595
    66556596\leavevmode
    66566597\begin{cfa}[aboveskip=0pt,belowskip=0pt]
     6598// C unsafe allocation
    66576599extern "C" {
    6658         // C unsafe allocation
    6659         void * malloc( size_t size );§\indexc{malloc}§
    6660         void * calloc( size_t dim, size_t size );§\indexc{calloc}§
    6661         void * realloc( void * ptr, size_t size );§\indexc{realloc}§
    6662         void * memalign( size_t align, size_t size );§\indexc{memalign}§
    6663         void * aligned_alloc( size_t align, size_t size );§\indexc{aligned_alloc}§
    6664         int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
    6665         void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );§\indexc{cmemalign}§ // CFA
    6666 
    6667         // C unsafe initialization/copy
    6668         void * memset( void * dest, int c, size_t size );§\indexc{memset}§
    6669         void * memcpy( void * dest, const void * src, size_t size );§\indexc{memcpy}§
    6670 }
    6671 
    6672 void * realloc( void * oaddr, size_t nalign, size_t size ); // CFA heap
     6600void * malloc( size_t size );§\indexc{memset}§
     6601void * calloc( size_t dim, size_t size );§\indexc{calloc}§
     6602void * realloc( void * ptr, size_t size );§\indexc{realloc}§
     6603void * memalign( size_t align, size_t size );§\indexc{memalign}§
     6604int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
     6605
     6606// C unsafe initialization/copy
     6607void * memset( void * dest, int c, size_t size );
     6608void * memcpy( void * dest, const void * src, size_t size );
     6609}
    66736610
    66746611forall( dtype T | sized(T) ) {
    6675         // §\CFA§ safe equivalents, i.e., implicit size specification
     6612// §\CFA§ safe equivalents, i.e., implicit size specification
    66766613        T * malloc( void );
    66776614        T * calloc( size_t dim );
    66786615        T * realloc( T * ptr, size_t size );
    66796616        T * memalign( size_t align );
    6680         T * cmemalign( size_t align, size_t dim  );
    66816617        T * aligned_alloc( size_t align );
    66826618        int posix_memalign( T ** ptr, size_t align );
    66836619
    6684         // §\CFA§ safe general allocation, fill, resize, alignment, array
     6620// §\CFA§ safe general allocation, fill, resize, array
    66856621        T * alloc( void );§\indexc{alloc}§
     6622        T * alloc( char fill );
    66866623        T * alloc( size_t dim );
     6624        T * alloc( size_t dim, char fill );
    66876625        T * alloc( T ptr[], size_t dim );
    6688         T * alloc_set( char fill );§\indexc{alloc_set}§
    6689         T * alloc_set( T fill );
    6690         T * alloc_set( size_t dim, char fill );
    6691         T * alloc_set( size_t dim, T fill );
    6692         T * alloc_set( size_t dim, const T fill[] );
    6693         T * alloc_set( T ptr[], size_t dim, char fill );
    6694 
    6695         T * alloc_align( size_t align );
    6696         T * alloc_align( size_t align, size_t dim );
    6697         T * alloc_align( T ptr[], size_t align ); // aligned realloc array
    6698         T * alloc_align( T ptr[], size_t align, size_t dim ); // aligned realloc array
    6699         T * alloc_align_set( size_t align, char fill );
    6700         T * alloc_align_set( size_t align, T fill );
    6701         T * alloc_align_set( size_t align, size_t dim, char fill );
    6702         T * alloc_align_set( size_t align, size_t dim, T fill );
    6703         T * alloc_align_set( size_t align, size_t dim, const T fill[] );
    6704         T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill );
    6705 
    6706         // §\CFA§ safe initialization/copy, i.e., implicit size specification
    6707         T * memset( T * dest, char fill );§\indexc{memset}§
     6626        T * alloc( T ptr[], size_t dim, char fill );
     6627
     6628// §\CFA§ safe general allocation, align, fill, array
     6629        T * align_alloc( size_t align );
     6630        T * align_alloc( size_t align, char fill );
     6631        T * align_alloc( size_t align, size_t dim );
     6632        T * align_alloc( size_t align, size_t dim, char fill );
     6633
     6634// §\CFA§ safe initialization/copy, i.e., implicit size specification
     6635        T * memset( T * dest, char c );§\indexc{memset}§
    67086636        T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
    67096637
    6710         // §\CFA§ safe initialization/copy, i.e., implicit size specification, array types
    6711         T * amemset( T dest[], char fill, size_t dim );
     6638// §\CFA§ safe initialization/copy array
     6639        T * amemset( T dest[], char c, size_t dim );
    67126640        T * amemcpy( T dest[], const T src[], size_t dim );
    67136641}
    67146642
    6715 // §\CFA§ allocation/deallocation and constructor/destructor, non-array types
    6716 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );§\indexc{new}§
    6717 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );§\indexc{delete}§
    6718 forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } )
     6643// §\CFA§ allocation/deallocation and constructor/destructor
     6644forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );§\indexc{new}§
     6645forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );§\indexc{delete}§
     6646forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
    67196647  void delete( T * ptr, Params rest );
    67206648
    6721 // §\CFA§ allocation/deallocation and constructor/destructor, array types
    6722 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
    6723 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
    6724 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } )
     6649// §\CFA§ allocation/deallocation and constructor/destructor, array
     6650forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
     6651forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
     6652forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
    67256653  void adelete( size_t dim, T arr[], Params rest );
    67266654\end{cfa}
Note: See TracChangeset for help on using the changeset viewer.