Changeset 4f0534f


Ignore:
Timestamp:
Mar 5, 2020, 1:00:36 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
f9723e8
Parents:
d870df3
Message:

update TIOBE information, restructure control-structures section, update storage-management section

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rd870df3 r4f0534f  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sat Jul 13 18:36:18 2019
    14 %% Update Count     : 3876
     13%% Last Modified On : Thu Mar  5 12:09:42 2020
     14%% Update Count     : 3885
    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 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.
    214 The top 3 rankings over the past 30 years are:
     213The 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.
     214The top 4 rankings over the past 35 years are:
    215215\begin{center}
    216216\setlength{\tabcolsep}{10pt}
    217 \begin{tabular}{@{}rccccccc@{}}
    218                 & 2018  & 2013  & 2008  & 2003  & 1998  & 1993  & 1988  \\ \hline
    219 Java    & 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             \\
     217\begin{tabular}{@{}rcccccccc@{}}
     218                & 2020  & 2015  & 2010  & 2005  & 2000  & 1995  & 1990  & 1985  \\ \hline
     219Java    & 1             & 2             & 1             & 2             & 3             & -             & -             & -             \\
     220\R{C}   & \R{2} & \R{1} & \R{2} & \R{1} & \R{1} & \R{2} & \R{1} & \R{1} \\
     221Python  & 3             & 7             & 6             & 6             & 22    & 21    & -             & -             \\
     222\CC             & 4             & 4             & 4             & 3             & 2             & 1             & 2             & 12    \\
    222223\end{tabular}
    223224\end{center}
     
    512513Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    513514\begin{cfa}
    514 int ®`®otype®`® = 3; §\C{// make keyword an identifier}§
    515 double ®`®forall®`® = 3.5;
     515int ®``®otype = 3; §\C{// make keyword an identifier}§
     516double ®``®forall = 3.5;
    516517\end{cfa}
    517518
     
    524525// include file uses the CFA keyword "with".
    525526#if ! defined( with ) §\C{// nesting ?}§
    526 #define with ®`®with®`® §\C{// make keyword an identifier}§
     527#define with ®``®with §\C{// make keyword an identifier}§
    527528#define __CFA_BFD_H__
    528529#endif
    529 
    530 ®#include_next <bfdlink.h> §\C{// must have internal check for multiple expansion}§
    531 ®
     530§{\color{red}\#\textbf{include\_next} <bfdlink.h>}§ §\C{// must have internal check for multiple expansion}§
    532531#if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§
    533532#undef with
     
    576575\section{Exponentiation Operator}
    577576
    578 C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation.
    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$.
     577C, \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$.
    580579The 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)©.
    581580
    582 As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
     581There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
    583582Integral 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).
    584 Overflow from large exponents or negative exponents return zero.
     583Overflow for a large exponent or negative exponent returns zero.
    585584Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
    586585\begin{cfa}
     
    5895881 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
    590589\end{cfa}
    591 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.
     590Note, ©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.
    592591Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
    593592The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
     
    598597OT ?®\®?( OT ep, unsigned long int y );
    599598\end{cfa}
    600 The user type ©T© must define multiplication, one, ©1©, and, ©*©.
     599The user type ©T© must define multiplication, one (©1©), and ©*©.
    601600
    602601
     
    626625
    627626
    628 \subsection{Loop Control}
    629 
    630 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
    631 \begin{itemize}
    632 \item
    633 An empty conditional implies ©1©.
    634 \item
    635 The up-to range ©~©\index{~@©~©} means exclusive range [M,N).
    636 \item
    637 The up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
    638 \item
    639 The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M).
    640 \item
    641 The 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
    649 The up-to range uses ©+=© for increment;
    650 \item
    651 The down-to range uses ©-=© for decrement.
    652 \item
    653 The 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}
     627%\section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}}
     628\subsection{\texorpdfstring{\LstKeywordStyle{case} Clause}{case Clause}}
     629
     630C restricts the ©case© clause of a ©switch© statement to a single value.
     631For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values.
     632Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C.
     633Therefore, the ©case© clause is extended with a list of values, as in:
    657634\begin{cquote}
    658 \begin{tabular}{@{}l|l@{}}
    659 \multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
    660 \hline
    661 \begin{cfa}
    662 sout | nlOff;
    663 while ®()® { sout | "empty"; break; } sout | nl;
    664 do { sout | "empty"; break; } while ®()®; sout | nl;
    665 for ®()® { sout | "empty"; break; } sout | nl;
    666 for ( ®0® ) { sout | "A"; } sout | "zero" | nl;
    667 for ( ®1® ) { sout | "A"; } sout | nl;
    668 for ( ®10® ) { sout | "A"; } sout | nl;
    669 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; } sout | nl;
    670 for ( ®10 -~= 1 ~ 2® ) { sout | "C"; } sout | nl;
    671 for ( ®0.5 ~ 5.5® ) { sout | "D"; } sout | nl;
    672 for ( ®5.5 -~ 0.5® ) { sout | "E"; } sout | nl;
    673 for ( ®i; 10® ) { sout | i; } sout | nl;
    674 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; } sout | nl;
    675 for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; } sout | nl;
    676 for ( ®i; 0.5 ~ 5.5® ) { sout | i; } sout | nl;
    677 for ( ®i; 5.5 -~ 0.5® ) { sout | i; } sout | nl;
    678 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; } sout | nl;
    679 for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; } sout | nl;
    680 enum { N = 10 };
    681 for ( ®N® ) { sout | "N"; } sout | nl;
    682 for ( ®i; N® ) { sout | i; } sout | nl;
    683 for ( ®i; N -~ 0® ) { sout | i; } sout | nl;
    684 const int start = 3, comp = 10, inc = 2;
    685 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; } sout | nl;
    686 for ( ®i; 1 ~ @® ) { if ( i > 10 ) break;
    687         sout | i; } sout | nl;
    688 for ( ®i; 10 -~ @® ) { if ( i < 0 ) break;
    689         sout | i; } sout | nl;
    690 for ( ®i; 2 ~ @ ~ 2® ) { if ( i > 10 ) break;
    691         sout | i; } sout | nl;
    692 for ( ®i; 2.1 ~ @ ~ @® ) { if ( i > 10.5 ) break;
    693         sout | i; i += 1.7; } sout | nl;
    694 for ( ®i; 10 -~ @ ~ 2® ) { if ( i < 0 ) break;
    695         sout | i; } sout | nl;
    696 for ( ®i; 12.1 ~ @ ~ @® ) { if ( i < 2.5 ) break;
    697         sout | i; i -= 1.7; } sout | nl;
    698 for ( ®i; 5 : j; -5 ~ @® ) { sout | i | j; } sout | nl;
    699 for ( ®i; 5 : j; -5 -~ @® ) { sout | i | j; } sout | nl;
    700 for ( ®i; 5 : j; -5 ~ @ ~ 2® ) { sout | i | j; } sout | nl;
    701 for ( ®i; 5 : j; -5 -~ @ ~ 2® ) { sout | i | j; } sout | nl;
    702 for ( ®j; -5 ~ @ : i; 5® ) { sout | i | j; } sout | nl;
    703 for ( ®j; -5 -~ @ : i; 5® ) { sout | i | j; } sout | nl;
    704 for ( ®j; -5 ~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
    705 for ( ®j; -5 -~ @ ~ 2 : i; 5® ) { sout | i | j; } sout | nl;
    706 for ( ®j; -5 -~ @ ~ 2 : i; 5 : k; 1.5 ~ @® ) {
    707         sout | i | j | k; } sout | nl;
    708 for ( ®j; -5 -~ @ ~ 2 : k; 1.5 ~ @ : i; 5® ) {
    709         sout | i | j | k; } sout | nl;
    710 for ( ®k; 1.5 ~ @ : j; -5 -~ @ ~ 2 : i; 5® ) {
    711         sout | i | j | k; } sout | nl;
     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}
     638switch ( i ) {
     639  case ®1, 3, 5®:
     640        ...
     641  case ®2, 4, 6®:
     642        ...
     643}
    712644\end{cfa}
    713645&
    714646\begin{cfa}
    715 
    716 empty
    717 empty
    718 empty
    719 zero
    720 A
    721 A A A A A A A A A A
    722 B B B B B
    723 C C C C C
    724 D D D D D
    725 E E E E E
    726 0 1 2 3 4 5 6 7 8 9
    727 1 3 5 7 9
    728 10 8 6 4 2
    729 0.5 1.5 2.5 3.5 4.5
    730 5.5 4.5 3.5 2.5 1.5
    731 2 4 6 8 10
    732 10 8 6 4 2
    733 
    734 N N N N N N N N N N
    735 0 1 2 3 4 5 6 7 8 9
    736 10 9 8 7 6 5 4 3 2 1
    737 
    738 3 6 9
    739 
    740 1 2 3 4 5 6 7 8 9 10
    741 
    742 10 9 8 7 6 5 4 3 2 1 0
    743 
    744 2 4 6 8 10
    745 
    746 2.1 3.8 5.5 7.2 8.9
    747 
    748 10 8 6 4 2 0
    749 
    750 12.1 10.4 8.7 7 5.3 3.6
    751 0 -5 1 -4 2 -3 3 -2 4 -1
    752 0 -5 1 -6 2 -7 3 -8 4 -9
    753 0 -5 1 -3 2 -1 3 1 4 3
    754 0 -5 1 -7 2 -9 3 -11 4 -13
    755 0 -5 1 -4 2 -3 3 -2 4 -1
    756 0 -5 1 -6 2 -7 3 -8 4 -9
    757 0 -5 1 -3 2 -1 3 1 4 3
    758 0 -5 1 -7 2 -9 3 -11 4 -13
    759 
    760 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    761 
    762 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    763 
    764 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     647switch ( 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
    765662\end{cfa}
    766663\end{tabular}
    767664\end{cquote}
    768 \caption{Loop Control Examples}
    769 \label{f:LoopControlExamples}
    770 \end{figure}
     665In addition, subranges are allowed to specify case values.\footnote{
     666gcc 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}
     668switch ( 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}
     675Lists of subranges are also allowed.
     676\begin{cfa}
     677case ®1~5, 12~21, 35~42®:
     678\end{cfa}
    771679
    772680
     
    977885
    978886
    979 %\section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}}
    980 \subsection{\texorpdfstring{\LstKeywordStyle{case} Statement}{case Statement}}
    981 
    982 C restricts the ©case© clause of a ©switch© statement to a single value.
    983 For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values.
    984 Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C.
    985 Therefore, 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}
    990 switch ( i ) {
    991   case ®1, 3, 5®:
     887\subsection{Non-terminating and Labelled \texorpdfstring{\LstKeywordStyle{fallthrough}}{Non-terminating and Labelled fallthrough}}
     888
     889The ©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}
     893choose ( ... ) {
     894  case 3:
     895        if ( ... ) {
     896                ... ®fallthru;® // goto case 4
     897        } else {
     898                ...
     899        }
     900        // implicit break
     901  case 4:
     902
     903
     904
     905
     906\end{cfa}
     907&
     908\begin{cfa}
     909choose ( ... ) {
     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
     922\end{cfa}
     923&
     924\begin{cfa}
     925choose ( ... ) {
     926  case 3:
     927        choose ( ... ) {
     928          case 4:
     929                for ( ... ) {
     930                        // multi-level transfer
     931                        ... ®fallthru common;®
     932                }
     933                ...
     934        }
    992935        ...
    993   case ®2, 4, 6®:
    994         ...
    995 }
     936  ®common:® // below fallthrough
     937                          // at case-clause level
     938\end{cfa}
     939\end{tabular}
     940\end{center}
     941The target label must be below the ©fallthrough© and may not be nested in a control structure, and
     942the target label must be at the same or higher level as the containing ©case© clause and located at
     943the same level as a ©case© clause; the target label may be case ©default©, but only associated
     944with the current ©switch©/©choose© statement.
     945
     946
     947\subsection{Loop Control}
     948
     949The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
     950\begin{itemize}
     951\item
     952The 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
     954An empty conditional implies comparison value of ©1© (true).
     955\item
     956A comparison N is implicit up-to exclusive range [0,N©®)®©.
     957\item
     958A comparison ©=© N is implicit up-to inclusive range [0,N©®]®©.
     959\item
     960The up-to range M ©~©\index{~@©~©} N means exclusive range [M,N©®)®©.
     961\item
     962The up-to range M ©~=©\index{~=@©~=©} N means inclusive range [M,N©®]®©.
     963\item
     964The down-to range M ©-~©\index{-~@©-~©} N means exclusive range [N,M©®)®©.
     965\item
     966The 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
     972The up-to range uses operator ©+=© for increment;
     973\item
     974The 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]
     986while ®()® { sout | "empty"; break; }
     987do { sout | "empty"; break; } while ®()®;
     988for ®()® { sout | "empty"; break; }
     989for ( ®0® ) { sout | "A"; } sout | "zero";
     990for ( ®1® ) { sout | "A"; }
     991for ( ®10® ) { sout | "A"; }
     992for ( ®= 10® ) { sout | "A"; }
     993for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
     994for ( ®10 -~= 1 ~ 2® ) { sout | "C"; }
     995for ( ®0.5 ~ 5.5® ) { sout | "D"; }
     996for ( ®5.5 -~ 0.5® ) { sout | "E"; }
     997for ( ®i; 10® ) { sout | i; }
     998for ( ®i; = 10® ) { sout | i; }
     999for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
     1000for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; }
     1001for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
     1002for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
     1003for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
     1004for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; }
     1005enum { N = 10 };
     1006for ( ®N® ) { sout | "N"; }
     1007for ( ®i; N® ) { sout | i; }
     1008for ( ®i; N -~ 0® ) { sout | i; }
     1009const int start = 3, comp = 10, inc = 2;
     1010for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
     1011for ( i; 1 ~ ®@® ) { if ( i > 10 ) break; sout | i; }
     1012for ( i; 10 -~ ®@® ) { if ( i < 0 ) break; sout | i; }
     1013for ( i; 2 ~ ®@® ~ 2 ) { if ( i > 10 ) break; sout | i; }
     1014for ( i; 2.1 ~ ®@® ~ ®@® ) { if ( i > 10.5 ) break; sout | i; i += 1.7; }
     1015for ( i; 10 -~ ®@® ~ 2 ) { if ( i < 0 ) break; sout | i; }
     1016for ( i; 12.1 ~ ®@® ~ ®@® ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; }
     1017for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
     1018for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
     1019for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
     1020for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
     1021for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
     1022for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
     1023for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
     1024for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
     1025for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
     1026for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
     1027for ( i; 5 ®:® k; 1.5 ~ @ ®:® j; -5 -~ @ ~ 2 ) { sout | i | j | k; }
    9961028\end{cfa}
    9971029&
    9981030\begin{cfa}
    999 switch ( i ) {
    1000   case 1: case 3 : case 5:
    1001         ...
    1002   case 2: case 4 : case 6:
    1003         ...
    1004 }
    1005 \end{cfa}
    1006 &
    1007 \begin{cfa}
    1008 
    1009 // odd values
    1010 
    1011 // even values
    1012 
    1013 
     1031empty
     1032empty
     1033empty
     1034zero
     1035A
     1036A A A A A A A A A A
     1037A A A A A A A A A A A
     1038B B B B B
     1039C C C C C
     1040D D D D D
     1041E E E E E
     10420 1 2 3 4 5 6 7 8 9
     10430 1 2 3 4 5 6 7 8 9 10
     10441 3 5 7 9
     104510 8 6 4 2
     10460.5 1.5 2.5 3.5 4.5
     10475.5 4.5 3.5 2.5 1.5
     10482 4 6 8 10
     104910 8 6 4 2
     1050
     1051N N N N N N N N N N
     10520 1 2 3 4 5 6 7 8 9
     105310 9 8 7 6 5 4 3 2 1
     1054
     10553 6 9
     10561 2 3 4 5 6 7 8 9 10
     105710 9 8 7 6 5 4 3 2 1 0
     10582 4 6 8 10
     10592.1 3.8 5.5 7.2 8.9
     106010 8 6 4 2 0
     106112.1 10.4 8.7 7. 5.3 3.6
     10620 -5 1 -4 2 -3 3 -2 4 -1
     10630 -5 1 -6 2 -7 3 -8 4 -9
     10640 -5 1 -3 2 -1 3 1 4 3
     10650 -5 1 -7 2 -9 3 -11 4 -13
     10660 -5 1 -4 2 -3 3 -2 4 -1
     10670 -5 1 -6 2 -7 3 -8 4 -9
     10680 -5 1 -3 2 -1 3 1 4 3
     10690 -5 1 -7 2 -9 3 -11 4 -13
     10700 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     10710 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
     10720 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5
    10141073\end{cfa}
    10151074\end{tabular}
    1016 \end{cquote}
    1017 In addition, subranges are allowed to specify case values.\footnote{
    1018 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.}
    1019 \begin{cfa}
    1020 switch ( i ) {
    1021   case ®1~5:® §\C{// 1, 2, 3, 4, 5}§
    1022         ...
    1023   case ®10~15:® §\C{// 10, 11, 12, 13, 14, 15}§
    1024         ...
    1025 }
    1026 \end{cfa}
    1027 Lists of subranges are also allowed.
    1028 \begin{cfa}
    1029 case ®1~5, 12~21, 35~42®:
    1030 \end{cfa}
    1031 
     1075\caption{Loop Control Examples}
     1076\label{f:LoopControlExamples}
     1077\end{figure}
    10321078
    10331079% for ()  => for ( ;; )
     
    65476593hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}).
    65486594All other C header files must be explicitly wrapped in ©extern "C"© to prevent name mangling.
    6549 For \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.
     6595This 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.
    65506596
    65516597
     
    65616607The 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.
    65626608
    6563 Storage management provides the following capabilities:
     6609C storage management provides the following capabilities:
    65646610\begin{description}
    6565 \item[fill]
    6566 after allocation the storage is filled with a specified character.
     6611\item[filled]
     6612after allocation with a specified character or value.
    65676613\item[resize]
    6568 an existing allocation is decreased or increased in size.
    6569 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.
     6614an existing allocation to decreased or increased its size.
     6615In 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.
    65706616For an increase in storage size, new storage after the copied data may be filled.
    6571 \item[alignment]
    6572 an allocation starts on a specified memory boundary, \eg, an address multiple of 64 or 128 for cache-line purposes.
     6617\item[align]
     6618an allocation on a specified memory boundary, \eg, an address multiple of 64 or 128 for cache-line purposes.
    65736619\item[array]
    65746620the allocation size is scaled to the specified number of array elements.
    65756621An array may be filled, resized, or aligned.
    65766622\end{description}
    6577 The table shows allocation routines supporting different combinations of storage-management capabilities:
    6578 \begin{center}
    6579 \begin{tabular}{@{}r|r|l|l|l|l@{}}
     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@{}}
    65806627\multicolumn{1}{c}{}&           & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
    65816628\hline
    65826629C               & ©malloc©                      & no                    & no            & no            & no    \\
    65836630                & ©calloc©                      & yes (0 only)  & no            & no            & yes   \\
    6584                 & ©realloc©                     & no/copy               & yes           & no            & no    \\
     6631                & ©realloc©                     & copy                  & yes           & no            & no    \\
    65856632                & ©memalign©            & no                    & no            & yes           & no    \\
     6633                & ©aligned_alloc©       & no                    & no            & yes           & no    \\
    65866634                & ©posix_memalign©      & no                    & no            & yes           & no    \\
    65876635\hline
    6588 C11             & ©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   \\
     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   \\
    65926644\end{tabular}
    6593 \end{center}
    6594 It 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.
     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}.
     6650Hence, initial allocation capabilities are remembered and maintained when resize requires copying.
     6651For 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.
     6652Without sticky properties it is dangerous to use ©realloc©, resulting in an idiom of manually performing the reallocation to maintain correctness.
     6653
    65956654
    65966655\leavevmode
    65976656\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6598 // C unsafe allocation
    65996657extern "C" {
    6600 void * malloc( size_t size );§\indexc{memset}§
    6601 void * calloc( size_t dim, size_t size );§\indexc{calloc}§
    6602 void * realloc( void * ptr, size_t size );§\indexc{realloc}§
    6603 void * memalign( size_t align, size_t size );§\indexc{memalign}§
    6604 int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
    6605 
    6606 // C unsafe initialization/copy
    6607 void * memset( void * dest, int c, size_t size );
    6608 void * memcpy( void * dest, const void * src, size_t size );
    6609 }
     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
     6672void * realloc( void * oaddr, size_t nalign, size_t size ); // CFA heap
    66106673
    66116674forall( dtype T | sized(T) ) {
    6612 // §\CFA§ safe equivalents, i.e., implicit size specification
     6675        // §\CFA§ safe equivalents, i.e., implicit size specification
    66136676        T * malloc( void );
    66146677        T * calloc( size_t dim );
    66156678        T * realloc( T * ptr, size_t size );
    66166679        T * memalign( size_t align );
     6680        T * cmemalign( size_t align, size_t dim  );
    66176681        T * aligned_alloc( size_t align );
    66186682        int posix_memalign( T ** ptr, size_t align );
    66196683
    6620 // §\CFA§ safe general allocation, fill, resize, array
     6684        // §\CFA§ safe general allocation, fill, resize, alignment, array
    66216685        T * alloc( void );§\indexc{alloc}§
    6622         T * alloc( char fill );
    66236686        T * alloc( size_t dim );
    6624         T * alloc( size_t dim, char fill );
    66256687        T * alloc( T ptr[], size_t dim );
    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}§
     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}§
    66366708        T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
    66376709
    6638 // §\CFA§ safe initialization/copy array
    6639         T * amemset( T dest[], char c, size_t dim );
     6710        // §\CFA§ safe initialization/copy, i.e., implicit size specification, array types
     6711        T * amemset( T dest[], char fill, size_t dim );
    66406712        T * amemcpy( T dest[], const T src[], size_t dim );
    66416713}
    66426714
    6643 // §\CFA§ allocation/deallocation and constructor/destructor
    6644 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );§\indexc{new}§
    6645 forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );§\indexc{delete}§
    6646 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
     6715// §\CFA§ allocation/deallocation and constructor/destructor, non-array types
     6716forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );§\indexc{new}§
     6717forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );§\indexc{delete}§
     6718forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } )
    66476719  void delete( T * ptr, Params rest );
    66486720
    6649 // §\CFA§ allocation/deallocation and constructor/destructor, array
    6650 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
    6651 forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
    6652 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
     6721// §\CFA§ allocation/deallocation and constructor/destructor, array types
     6722forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
     6723forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
     6724forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } )
    66536725  void adelete( size_t dim, T arr[], Params rest );
    66546726\end{cfa}
Note: See TracChangeset for help on using the changeset viewer.