Changeset 58fe85a for doc/user/user.tex
- Timestamp:
- Jan 7, 2021, 3:27:00 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 2b4daf2, 64aeca0
- Parents:
- 3c64c668 (diff), eef8dfb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
doc/user/user.tex (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r3c64c668 r58fe85a 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sat Jul 13 18:36:18 201914 %% Update Count : 3 87613 %% Last Modified On : Mon Oct 5 08:57:29 2020 14 %% Update Count : 3998 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 30 30 \usepackage{upquote} % switch curled `'" to straight 31 31 \usepackage{calc} 32 \usepackage{xspace}33 32 \usepackage{varioref} % extended references 34 \usepackage{listings} % format program code 33 \usepackage[labelformat=simple,aboveskip=0pt,farskip=0pt]{subfig} 34 \renewcommand{\thesubfigure}{\alph{subfigure})} 35 35 \usepackage[flushmargin]{footmisc} % support label/reference in footnote 36 36 \usepackage{latexsym} % \Box glyph 37 37 \usepackage{mathptmx} % better math font with "times" 38 38 \usepackage[usenames]{color} 39 \input{common} % common CFA document macros 40 \usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref} 41 \usepackage{breakurl} 42 43 \usepackage[pagewise]{lineno} 44 \renewcommand{\linenumberfont}{\scriptsize\sffamily} 45 \usepackage[firstpage]{draftwatermark} 46 \SetWatermarkLightness{0.9} 47 48 % Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore 49 % removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR 50 % AFTER HYPERREF. 51 \renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}} 52 53 \setlength{\topmargin}{-0.45in} % move running title into header 54 \setlength{\headsep}{0.25in} 55 56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 57 58 \CFAStyle % use default CFA format-style 59 \lstnewenvironment{C++}[1][] % use C++ style 60 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®},#1}} 61 {} 62 39 \newcommand{\CFALatin}{} 63 40 % inline code ©...© (copyright symbol) emacs: C-q M-) 64 41 % red highlighting ®...® (registered trademark symbol) emacs: C-q M-. … … 68 45 % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^ 69 46 % math escape $...$ (dollar symbol) 47 \input{common} % common CFA document macros 48 \usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref} 49 \usepackage{breakurl} 50 51 \renewcommand\footnoterule{\kern -3pt\rule{0.3\linewidth}{0.15pt}\kern 2pt} 52 53 \usepackage[pagewise]{lineno} 54 \renewcommand{\linenumberfont}{\scriptsize\sffamily} 55 \usepackage[firstpage]{draftwatermark} 56 \SetWatermarkLightness{0.9} 57 58 % Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore 59 % removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR 60 % AFTER HYPERREF. 61 \renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}} 62 63 \setlength{\topmargin}{-0.45in} % move running title into header 64 \setlength{\headsep}{0.25in} 65 66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 67 68 \CFAStyle % use default CFA format-style 69 \lstnewenvironment{C++}[1][] % use C++ style 70 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®},#1}} 71 {} 72 73 \newsavebox{\myboxA} 74 \newsavebox{\myboxB} 70 75 71 76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 79 84 \newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}} 80 85 \newcommand{\KWC}{K-W C\xspace} 81 82 \newsavebox{\LstBox}83 86 84 87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 211 214 Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction. 212 215 For 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 30years are:216 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. 217 The top 4 rankings over the past 35 years are: 215 218 \begin{center} 216 219 \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 \\ 220 \begin{tabular}{@{}rcccccccc@{}} 221 & 2020 & 2015 & 2010 & 2005 & 2000 & 1995 & 1990 & 1985 \\ \hline 222 Java & 1 & 2 & 1 & 2 & 3 & - & - & - \\ 223 \R{C} & \R{2} & \R{1} & \R{2} & \R{1} & \R{1} & \R{2} & \R{1} & \R{1} \\ 224 Python & 3 & 7 & 6 & 6 & 22 & 21 & - & - \\ 225 \CC & 4 & 4 & 4 & 3 & 2 & 1 & 2 & 12 \\ 222 226 \end{tabular} 223 227 \end{center} … … 252 256 253 257 The signature feature of \CFA is \emph{\Index{overload}able} \Index{parametric-polymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name): 254 \begin{ lstlisting}258 \begin{cfa} 255 259 ®forall( otype T )® T identity( T val ) { return val; } 256 260 int forty_two = identity( 42 ); §\C{// T is bound to int, forty\_two == 42}§ 257 \end{ lstlisting}261 \end{cfa} 258 262 % extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions. 259 263 \CFA{}\hspace{1pt}'s polymorphism was originally formalized by \Index*{Glen Ditchfield}\index{Ditchfield, Glen}~\cite{Ditchfield92}, and first implemented by \Index*{Richard Bilson}\index{Bilson, Richard}~\cite{Bilson03}. … … 274 278 \begin{comment} 275 279 A simple example is leveraging the existing type-unsafe (©void *©) C ©bsearch© to binary search a sorted floating array: 276 \begin{ lstlisting}280 \begin{cfa} 277 281 void * bsearch( const void * key, const void * base, size_t dim, size_t size, 278 282 int (* compar)( const void *, const void * )); … … 283 287 double key = 5.0, vals[10] = { /* 10 sorted floating values */ }; 284 288 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); §\C{// search sorted array}§ 285 \end{ lstlisting}289 \end{cfa} 286 290 which can be augmented simply with a polymorphic, type-safe, \CFA-overloaded wrappers: 287 \begin{ lstlisting}291 \begin{cfa} 288 292 forall( otype T | { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t size ) { 289 293 int comp( const void * t1, const void * t2 ) { /* as above with double changed to T */ } … … 296 300 double * val = bsearch( 5.0, vals, 10 ); §\C{// selection based on return type}§ 297 301 int posn = bsearch( 5.0, vals, 10 ); 298 \end{ lstlisting}302 \end{cfa} 299 303 The nested function ©comp© provides the hidden interface from typed \CFA to untyped (©void *©) C, plus the cast of the result. 300 304 Providing a hidden ©comp© function in \CC is awkward as lambdas do not use C calling-conventions and template declarations cannot appear at block scope. … … 304 308 \CFA has replacement libraries condensing hundreds of existing C functions into tens of \CFA overloaded functions, all without rewriting the actual computations. 305 309 For example, it is possible to write a type-safe \CFA wrapper ©malloc© based on the C ©malloc©: 306 \begin{ lstlisting}310 \begin{cfa} 307 311 forall( dtype T | sized(T) ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); } 308 312 int * ip = malloc(); §\C{// select type and size from left-hand side}§ 309 313 double * dp = malloc(); 310 314 struct S {...} * sp = malloc(); 311 \end{ lstlisting}315 \end{cfa} 312 316 where the return type supplies the type/size of the allocation, which is impossible in most type systems. 313 317 \end{comment} … … 512 516 Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism: 513 517 \begin{cfa} 514 int ®` ®otype®`®= 3; §\C{// make keyword an identifier}§515 double ®` ®forall®`®= 3.5;518 int ®``®otype = 3; §\C{// make keyword an identifier}§ 519 double ®``®forall = 3.5; 516 520 \end{cfa} 517 521 … … 524 528 // include file uses the CFA keyword "with". 525 529 #if ! defined( with ) §\C{// nesting ?}§ 526 #define with ®` ®with®`®§\C{// make keyword an identifier}§530 #define with ®``®with §\C{// make keyword an identifier}§ 527 531 #define __CFA_BFD_H__ 528 532 #endif 529 530 ®#include_next <bfdlink.h> §\C{// must have internal check for multiple expansion}§ 531 ® 533 §{\color{red}\#\textbf{include\_next} <bfdlink.h>}§ §\C{// must have internal check for multiple expansion}§ 532 534 #if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§ 533 535 #undef with … … 576 578 \section{Exponentiation Operator} 577 579 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$.580 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. 581 \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$. 580 582 The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©. 581 583 582 As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.584 There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types. 583 585 Integral 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 f rom large exponents or negative exponents returnzero.586 Overflow for a large exponent or negative exponent returns zero. 585 587 Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative. 586 588 \begin{cfa} … … 589 591 1 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i 590 592 \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.593 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. 592 594 Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©. 593 595 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available. … … 598 600 OT ?®\®?( OT ep, unsigned long int y ); 599 601 \end{cfa} 600 The user type ©T© must define multiplication, one , ©1©, and,©*©.602 The user type ©T© must define multiplication, one (©1©), and ©*©. 601 603 602 604 … … 626 628 627 629 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} 630 %\section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}} 631 \subsection{\texorpdfstring{\LstKeywordStyle{case} Clause}{case Clause}} 632 633 C restricts the ©case© clause of a ©switch© statement to a single value. 634 For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values. 635 Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C. 636 Therefore, the ©case© clause is extended with a list of values, as in: 657 637 \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; 638 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}} 639 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\ 640 \begin{cfa} 641 switch ( i ) { 642 case ®1, 3, 5®: 643 ... 644 case ®2, 4, 6®: 645 ... 646 } 712 647 \end{cfa} 713 648 & 714 649 \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 650 switch ( i ) { 651 case 1: case 3 : case 5: 652 ... 653 case 2: case 4 : case 6: 654 ... 655 } 656 \end{cfa} 657 & 658 \begin{cfa} 659 660 // odd values 661 662 // even values 663 664 765 665 \end{cfa} 766 666 \end{tabular} 767 667 \end{cquote} 768 \caption{Loop Control Examples} 769 \label{f:LoopControlExamples} 770 \end{figure} 668 In addition, subranges are allowed to specify case values.\footnote{ 669 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.} 670 \begin{cfa} 671 switch ( i ) { 672 case ®1~5:® §\C{// 1, 2, 3, 4, 5}§ 673 ... 674 case ®10~15:® §\C{// 10, 11, 12, 13, 14, 15}§ 675 ... 676 } 677 \end{cfa} 678 Lists of subranges are also allowed. 679 \begin{cfa} 680 case ®1~5, 12~21, 35~42®: 681 \end{cfa} 771 682 772 683 … … 977 888 978 889 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®: 890 \subsection{Non-terminating and Labelled \texorpdfstring{\LstKeywordStyle{fallthrough}}{Non-terminating and Labelled fallthrough}} 891 892 The ©fallthrough© clause may be non-terminating within a ©case© clause or have a target label to common code from multiple case clauses. 893 \begin{center} 894 \begin{tabular}{@{}lll@{}} 895 \begin{cfa} 896 choose ( ... ) { 897 case 3: 898 if ( ... ) { 899 ... ®fallthru;® // goto case 4 900 } else { 901 ... 902 } 903 // implicit break 904 case 4: 905 906 907 908 909 \end{cfa} 910 & 911 \begin{cfa} 912 choose ( ... ) { 913 case 3: 914 ... ®fallthrough common;® 915 case 4: 916 ... ®fallthrough common;® 917 918 ®common:® // below fallthrough 919 // at case-clause level 920 ... // common code for cases 3/4 921 // implicit break 922 case 4: 923 924 925 \end{cfa} 926 & 927 \begin{cfa} 928 choose ( ... ) { 929 case 3: 930 choose ( ... ) { 931 case 4: 932 for ( ... ) { 933 // multi-level transfer 934 ... ®fallthru common;® 935 } 936 ... 937 } 992 938 ... 993 case ®2, 4, 6®: 994 ... 995 } 939 ®common:® // below fallthrough 940 // at case-clause level 941 \end{cfa} 942 \end{tabular} 943 \end{center} 944 The target label must be below the ©fallthrough© and may not be nested in a control structure, and 945 the target label must be at the same or higher level as the containing ©case© clause and located at 946 the same level as a ©case© clause; the target label may be case ©default©, but only associated 947 with the current ©switch©/©choose© statement. 948 949 \begin{figure} 950 \begin{tabular}{@{}l|l@{}} 951 \multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\ 952 \hline 953 \begin{cfa}[xleftmargin=0pt] 954 while ®()® { sout | "empty"; break; } 955 do { sout | "empty"; break; } while ®()®; 956 for ®()® { sout | "empty"; break; } 957 for ( ®0® ) { sout | "A"; } sout | "zero"; 958 for ( ®1® ) { sout | "A"; } 959 for ( ®10® ) { sout | "A"; } 960 for ( ®= 10® ) { sout | "A"; } 961 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; } 962 for ( ®10 -~= 1 ~ 2® ) { sout | "C"; } 963 for ( ®0.5 ~ 5.5® ) { sout | "D"; } 964 for ( ®5.5 -~ 0.5® ) { sout | "E"; } 965 for ( ®i; 10® ) { sout | i; } 966 for ( ®i; = 10® ) { sout | i; } 967 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; } 968 for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; } 969 for ( ®i; 0.5 ~ 5.5® ) { sout | i; } 970 for ( ®i; 5.5 -~ 0.5® ) { sout | i; } 971 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; } 972 for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; } 973 enum { N = 10 }; 974 for ( ®N® ) { sout | "N"; } 975 for ( ®i; N® ) { sout | i; } 976 for ( ®i; N -~ 0® ) { sout | i; } 977 const int start = 3, comp = 10, inc = 2; 978 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; } 979 for ( i; 1 ~ ®@® ) { if ( i > 10 ) break; sout | i; } 980 for ( i; 10 -~ ®@® ) { if ( i < 0 ) break; sout | i; } 981 for ( i; 2 ~ ®@® ~ 2 ) { if ( i > 10 ) break; sout | i; } 982 for ( i; 2.1 ~ ®@® ~ ®@® ) { if ( i > 10.5 ) break; sout | i; i += 1.7; } 983 for ( i; 10 -~ ®@® ~ 2 ) { if ( i < 0 ) break; sout | i; } 984 for ( i; 12.1 ~ ®@® ~ ®@® ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; } 985 for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; } 986 for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; } 987 for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; } 988 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; } 989 for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; } 990 for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; } 991 for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; } 992 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; } 993 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; } 994 for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; } 995 for ( i; 5 ®:® k; 1.5 ~ @ ®:® j; -5 -~ @ ~ 2 ) { sout | i | j | k; } 996 996 \end{cfa} 997 997 & 998 998 \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 999 empty 1000 empty 1001 empty 1002 zero 1003 A 1004 A A A A A A A A A A 1005 A A A A A A A A A A A 1006 B B B B B 1007 C C C C C 1008 D D D D D 1009 E E E E E 1010 0 1 2 3 4 5 6 7 8 9 1011 0 1 2 3 4 5 6 7 8 9 10 1012 1 3 5 7 9 1013 10 8 6 4 2 1014 0.5 1.5 2.5 3.5 4.5 1015 5.5 4.5 3.5 2.5 1.5 1016 2 4 6 8 10 1017 10 8 6 4 2 1018 1019 N N N N N N N N N N 1020 0 1 2 3 4 5 6 7 8 9 1021 10 9 8 7 6 5 4 3 2 1 1022 1023 3 6 9 1024 1 2 3 4 5 6 7 8 9 10 1025 10 9 8 7 6 5 4 3 2 1 0 1026 2 4 6 8 10 1027 2.1 3.8 5.5 7.2 8.9 1028 10 8 6 4 2 0 1029 12.1 10.4 8.7 7. 5.3 3.6 1030 0 -5 1 -4 2 -3 3 -2 4 -1 1031 0 -5 1 -6 2 -7 3 -8 4 -9 1032 0 -5 1 -3 2 -1 3 1 4 3 1033 0 -5 1 -7 2 -9 3 -11 4 -13 1034 0 -5 1 -4 2 -3 3 -2 4 -1 1035 0 -5 1 -6 2 -7 3 -8 4 -9 1036 0 -5 1 -3 2 -1 3 1 4 3 1037 0 -5 1 -7 2 -9 3 -11 4 -13 1038 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5 1039 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5 1040 0 -5 1.5 1 -7 2.5 2 -9 3.5 3 -11 4.5 4 -13 5.5 1014 1041 \end{cfa} 1015 1042 \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 1043 \caption{Loop Control Examples} 1044 \label{f:LoopControlExamples} 1045 \end{figure} 1032 1046 1033 1047 % for () => for ( ;; ) … … 1040 1054 1041 1055 1056 \subsection{Loop Control} 1057 1058 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}). 1059 \begin{itemize} 1060 \item 1061 The loop index is polymorphic in the type of the comparison value N (when the start value is implicit) or the start value M. 1062 \item 1063 An empty conditional implies comparison value of ©1© (true). 1064 \item 1065 A comparison N is implicit up-to exclusive range [0,N©®)®©. 1066 \item 1067 A comparison ©=© N is implicit up-to inclusive range [0,N©®]®©. 1068 \item 1069 The up-to range M ©~©\index{~@©~©} N means exclusive range [M,N©®)®©. 1070 \item 1071 The up-to range M ©~=©\index{~=@©~=©} N means inclusive range [M,N©®]®©. 1072 \item 1073 The down-to range M ©-~©\index{-~@©-~©} N means exclusive range [N,M©®)®©. 1074 \item 1075 The down-to range M ©-~=©\index{-~=@©-~=©} N means inclusive range [N,M©®]®©. 1076 \item 1077 ©0© is the implicit start value; 1078 \item 1079 ©1© is the implicit increment value. 1080 \item 1081 The up-to range uses operator ©+=© for increment; 1082 \item 1083 The down-to range uses operator ©-=© for decrement. 1084 \item 1085 ©@© means put nothing in this field. 1086 \item 1087 ©:© means start another index. 1088 \end{itemize} 1089 1090 1042 1091 %\subsection{\texorpdfstring{Labelled \protect\lstinline@continue@ / \protect\lstinline@break@}{Labelled continue / break}} 1043 1092 \subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}} … … 1049 1098 for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement. 1050 1099 \VRef[Figure]{f:MultiLevelExit} shows ©continue© and ©break© indicating the specific control structure, and the corresponding C program using only ©goto© and labels. 1051 The innermost loop has 7exit points, which cause continuation or termination of one or more of the 7 \Index{nested control-structure}s.1100 The innermost loop has 8 exit points, which cause continuation or termination of one or more of the 7 \Index{nested control-structure}s. 1052 1101 1053 1102 \begin{figure} 1054 \begin{tabular}{@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}} 1055 \multicolumn{1}{@{\hspace{\parindentlnth}}c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}} \\ 1056 \begin{cfa} 1057 ®LC:® { 1058 ... §declarations§ ... 1059 ®LS:® switch ( ... ) { 1060 case 3: 1061 ®LIF:® if ( ... ) { 1062 ®LF:® for ( ... ) { 1063 ®LW:® while ( ... ) { 1064 ... break ®LC®; ... 1065 ... break ®LS®; ... 1066 ... break ®LIF®; ... 1067 ... continue ®LF;® ... 1068 ... break ®LF®; ... 1069 ... continue ®LW®; ... 1070 ... break ®LW®; ... 1071 } // while 1072 } // for 1073 } else { 1074 ... break ®LIF®; ... 1075 } // if 1076 } // switch 1103 \centering 1104 \begin{lrbox}{\myboxA} 1105 \begin{cfa}[tabsize=3] 1106 ®Compound:® { 1107 ®Try:® try { 1108 ®For:® for ( ... ) { 1109 ®While:® while ( ... ) { 1110 ®Do:® do { 1111 ®If:® if ( ... ) { 1112 ®Switch:® switch ( ... ) { 1113 case 3: 1114 ®break Compound®; 1115 ®break Try®; 1116 ®break For®; /* or */ ®continue For®; 1117 ®break While®; /* or */ ®continue While®; 1118 ®break Do®; /* or */ ®continue Do®; 1119 ®break If®; 1120 ®break Switch®; 1121 } // switch 1122 } else { 1123 ... ®break If®; ... // terminate if 1124 } // if 1125 } while ( ... ); // do 1126 } // while 1127 } // for 1128 } ®finally® { // always executed 1129 } // try 1077 1130 } // compound 1078 1131 \end{cfa} 1079 & 1080 \begin{cfa} 1132 \end{lrbox} 1133 1134 \begin{lrbox}{\myboxB} 1135 \begin{cfa}[tabsize=3] 1081 1136 { 1082 ... §declarations§ ... 1083 switch ( ... ) { 1084 case 3: 1085 if ( ... ) { 1086 for ( ... ) { 1087 while ( ... ) { 1088 ... goto ®LC®; ... 1089 ... goto ®LS®; ... 1090 ... goto ®LIF®; ... 1091 ... goto ®LFC®; ... 1092 ... goto ®LFB®; ... 1093 ... goto ®LWC®; ... 1094 ... goto ®LWB®; ... 1095 ®LWC®: ; } ®LWB:® ; 1096 ®LFC:® ; } ®LFB:® ; 1097 } else { 1098 ... goto ®LIF®; ... 1099 } ®L3:® ; 1100 } ®LS:® ; 1101 } ®LC:® ; 1102 \end{cfa} 1103 & 1104 \begin{cfa} 1105 1106 1107 1108 1109 1110 1111 1112 // terminate compound 1113 // terminate switch 1114 // terminate if 1115 // continue loop 1116 // terminate loop 1117 // continue loop 1118 // terminate loop 1119 1120 1121 1122 // terminate if 1123 1124 1125 1126 \end{cfa} 1127 \end{tabular} 1137 1138 ®ForC:® for ( ... ) { 1139 ®WhileC:® while ( ... ) { 1140 ®DoC:® do { 1141 if ( ... ) { 1142 switch ( ... ) { 1143 case 3: 1144 ®goto Compound®; 1145 ®goto Try®; 1146 ®goto ForB®; /* or */ ®goto ForC®; 1147 ®goto WhileB®; /* or */ ®goto WhileC®; 1148 ®goto DoB®; /* or */ ®goto DoC®; 1149 ®goto If®; 1150 ®goto Switch®; 1151 } ®Switch:® ; 1152 } else { 1153 ... ®goto If®; ... // terminate if 1154 } ®If:®; 1155 } while ( ... ); ®DoB:® ; 1156 } ®WhileB:® ; 1157 } ®ForB:® ; 1158 1159 1160 } ®Compound:® ; 1161 \end{cfa} 1162 \end{lrbox} 1163 1164 \subfloat[\CFA]{\label{f:CFibonacci}\usebox\myboxA} 1165 \hspace{2pt} 1166 \vrule 1167 \hspace{2pt} 1168 \subfloat[C]{\label{f:CFAFibonacciGen}\usebox\myboxB} 1128 1169 \caption{Multi-level Exit} 1129 1170 \label{f:MultiLevelExit} … … 1380 1421 try { 1381 1422 f(...); 1382 } catch( E e ; §boolean-predicate§ ) { §\C [8cm]{// termination handler}§1423 } catch( E e ; §boolean-predicate§ ) { §\C{// termination handler}§ 1383 1424 // recover and continue 1384 } catchResume( E e ; §boolean-predicate§ ) { §\C{// resumption handler} \CRT§1425 } catchResume( E e ; §boolean-predicate§ ) { §\C{// resumption handler}§ 1385 1426 // repair and return 1386 1427 } finally { … … 3445 3486 For implicit formatted input, the common case is reading a sequence of values separated by whitespace, where the type of an input constant must match with the type of the input variable. 3446 3487 \begin{cquote} 3447 \begin{lrbox}{\ LstBox}3488 \begin{lrbox}{\myboxA} 3448 3489 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 3449 3490 int x; double y char z; … … 3451 3492 \end{lrbox} 3452 3493 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{3em}}l@{}} 3453 \multicolumn{1}{@{}l@{}}{\usebox\ LstBox} \\3494 \multicolumn{1}{@{}l@{}}{\usebox\myboxA} \\ 3454 3495 \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CC}} & \multicolumn{1}{c}{\textbf{Python}} \\ 3455 3496 \begin{cfa}[aboveskip=0pt,belowskip=0pt] … … 6547 6588 hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}). 6548 6589 All 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 manyC header-files through checks for preprocessor variable ©__cplusplus©, which adds appropriate ©extern "C"© qualifiers.6590 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. 6550 6591 6551 6592 … … 6561 6602 The 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. 6562 6603 6563 Storage management provides the following capabilities:6604 C storage management provides the following capabilities: 6564 6605 \begin{description} 6565 \item[fill ]6566 after allocation the storage is filled with a specified character.6606 \item[filled] 6607 after allocation with a specified character or value. 6567 6608 \item[resize] 6568 an existing allocation is decreased or increased insize.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 .6609 an existing allocation to decreased or increased its size. 6610 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. 6570 6611 For an increase in storage size, new storage after the copied data may be filled. 6571 \item[align ment]6572 an allocation startson a specified memory boundary, \eg, an address multiple of 64 or 128 for cache-line purposes.6612 \item[align] 6613 an allocation on a specified memory boundary, \eg, an address multiple of 64 or 128 for cache-line purposes. 6573 6614 \item[array] 6574 6615 the allocation size is scaled to the specified number of array elements. 6575 6616 An array may be filled, resized, or aligned. 6576 6617 \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@{}} 6618 \VRef[Table]{t:AllocationVersusCapabilities} shows allocation routines supporting different combinations of storage-management capabilities. 6619 \begin{table} 6620 \centering 6621 \begin{minipage}{0.75\textwidth} 6622 \begin{tabular}{@{}r|l|l|l|l|l@{}} 6580 6623 \multicolumn{1}{c}{}& & \multicolumn{1}{c|}{fill} & resize & alignment & array \\ 6581 6624 \hline 6582 6625 C & ©malloc© & no & no & no & no \\ 6583 6626 & ©calloc© & yes (0 only) & no & no & yes \\ 6584 & ©realloc© & no/copy& yes & no & no \\6627 & ©realloc© & copy & yes & no & no \\ 6585 6628 & ©memalign© & no & no & yes & no \\ 6629 & ©aligned_alloc©\footnote{Same as ©memalign© but size is an integral multiple of alignment, which is universally ignored.} 6630 & no & no & yes & no \\ 6586 6631 & ©posix_memalign© & no & no & yes & no \\ 6632 & ©valloc© & no & no & yes (page size)& no \\ 6633 & ©pvalloc©\footnote{Same as ©valloc© but rounds size to multiple of page size.} 6634 & no & no & yes (page size)& no \\ 6587 6635 \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 & yes & no & yes \\ 6639 & ©alloc_set© & yes & yes & no & yes \\ 6640 & ©alloc_align© & no & yes & yes & yes \\ 6641 & ©alloc_align_set© & yes & yes & yes & yes \\ 6592 6642 \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. 6643 \end{minipage} 6644 \caption{Allocation Routines versus Storage-Management Capabilities} 6645 \label{t:AllocationVersusCapabilities} 6646 \end{table} 6647 6648 \CFA memory management extends the type safety of all allocations by using the type of the left-hand-side type to determine the allocation size and return a matching type for the new storage. 6649 Type-safe allocation is provided for all C allocation routines and new \CFA allocation routines, \eg in 6650 \begin{cfa} 6651 int * ip = (int *)malloc( sizeof(int) ); §\C{// C}§ 6652 int * ip = malloc(); §\C{// \CFA type-safe version of C malloc}§ 6653 int * ip = alloc(); §\C{// \CFA type-safe uniform alloc}§ 6654 \end{cfa} 6655 the latter two allocations determine the allocation size from the type of ©p© (©int©) and cast the pointer to the allocated storage to ©int *©. 6656 6657 \CFA memory management extends allocation safety by implicitly honouring all alignment requirements, \eg in 6658 \begin{cfa} 6659 struct S { int i; } __attribute__(( aligned( 128 ) )); // cache-line alignment 6660 S * sp = malloc(); §\C{// honour type alignment}§ 6661 \end{cfa} 6662 the storage allocation is implicitly aligned to 128 rather than the default 16. 6663 The alignment check is performed at compile time so there is no runtime cost. 6664 6665 \CFA memory management extends the resize capability with the notion of \newterm{sticky properties}. 6666 Hence, initial allocation capabilities are remembered and maintained when resize requires copying. 6667 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. 6668 Without sticky properties it is dangerous to use ©realloc©, resulting in an idiom of manually performing the reallocation to maintain correctness. 6669 \begin{cfa} 6670 6671 \end{cfa} 6672 6673 \CFA memory management extends allocation to support constructors for initialization of allocated storage, \eg in 6674 \begin{cfa} 6675 struct S { int i; }; §\C{// cache-line aglinment}§ 6676 void ?{}( S & s, int i ) { s.i = i; } 6677 // assume ?|? operator for printing an S 6678 6679 S & sp = *®new®( 3 ); §\C{// call constructor after allocation}§ 6680 sout | sp.i; 6681 ®delete®( &sp ); 6682 6683 S * spa = ®anew®( 10, 5 ); §\C{// allocate array and initialize each array element}§ 6684 for ( i; 10 ) sout | spa[i] | nonl; 6685 sout | nl; 6686 ®adelete®( 10, spa ); 6687 \end{cfa} 6688 Allocation routines ©new©/©anew© allocate a variable/array and initialize storage using the allocated type's constructor. 6689 Note, the matching deallocation routines ©delete©/©adelete©. 6595 6690 6596 6691 \leavevmode 6597 6692 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 6598 // C unsafe allocation6599 6693 extern "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 } 6694 // C unsafe allocation 6695 void * malloc( size_t size );§\indexc{malloc}§ 6696 void * calloc( size_t dim, size_t size );§\indexc{calloc}§ 6697 void * realloc( void * ptr, size_t size );§\indexc{realloc}§ 6698 void * memalign( size_t align, size_t size );§\indexc{memalign}§ 6699 void * aligned_alloc( size_t align, size_t size );§\indexc{aligned_alloc}§ 6700 int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§ 6701 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );§\indexc{cmemalign}§ // CFA 6702 6703 // C unsafe initialization/copy 6704 void * memset( void * dest, int c, size_t size );§\indexc{memset}§ 6705 void * memcpy( void * dest, const void * src, size_t size );§\indexc{memcpy}§ 6706 } 6707 6708 void * realloc( void * oaddr, size_t nalign, size_t size ); // CFA heap 6610 6709 6611 6710 forall( dtype T | sized(T) ) { 6612 // §\CFA§ safe equivalents, i.e., implicit size specification6711 // §\CFA§ safe equivalents, i.e., implicit size specification 6613 6712 T * malloc( void ); 6614 6713 T * calloc( size_t dim ); 6615 6714 T * realloc( T * ptr, size_t size ); 6616 6715 T * memalign( size_t align ); 6716 T * cmemalign( size_t align, size_t dim ); 6617 6717 T * aligned_alloc( size_t align ); 6618 6718 int posix_memalign( T ** ptr, size_t align ); 6619 6719 6620 // §\CFA§ safe general allocation, fill, resize, array 6621 T * alloc( void );§\indexc{alloc}§ 6622 T * alloc( char fill ); 6623 T * alloc( size_t dim ); 6624 T * alloc( size_t dim, char fill ); 6625 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}§ 6720 // §\CFA§ safe general allocation, fill, resize, alignment, array 6721 T * alloc( void );§\indexc{alloc}§ §\C[3.5in]{// variable, T size}§ 6722 T * alloc( size_t dim ); §\C{// array[dim], T size elements}§ 6723 T * alloc( T ptr[], size_t dim ); §\C{// realloc array[dim], T size elements}§ 6724 6725 T * alloc_set( char fill );§\indexc{alloc_set}§ §\C{// variable, T size, fill bytes with value}§ 6726 T * alloc_set( T fill ); §\C{// variable, T size, fill with value}§ 6727 T * alloc_set( size_t dim, char fill ); §\C{// array[dim], T size elements, fill bytes with value}§ 6728 T * alloc_set( size_t dim, T fill ); §\C{// array[dim], T size elements, fill elements with value}§ 6729 T * alloc_set( size_t dim, const T fill[] ); §\C{// array[dim], T size elements, fill elements with array}§ 6730 T * alloc_set( T ptr[], size_t dim, char fill ); §\C{// realloc array[dim], T size elements, fill bytes with value}§ 6731 6732 T * alloc_align( size_t align ); §\C{// aligned variable, T size}§ 6733 T * alloc_align( size_t align, size_t dim ); §\C{// aligned array[dim], T size elements}§ 6734 T * alloc_align( T ptr[], size_t align ); §\C{// realloc new aligned array}§ 6735 T * alloc_align( T ptr[], size_t align, size_t dim ); §\C{// realloc new aligned array[dim]}§ 6736 6737 T * alloc_align_set( size_t align, char fill ); §\C{// aligned variable, T size, fill bytes with value}§ 6738 T * alloc_align_set( size_t align, T fill ); §\C{// aligned variable, T size, fill with value}§ 6739 T * alloc_align_set( size_t align, size_t dim, char fill ); §\C{// aligned array[dim], T size elements, fill bytes with value}§ 6740 T * alloc_align_set( size_t align, size_t dim, T fill ); §\C{// aligned array[dim], T size elements, fill elements with value}§ 6741 T * alloc_align_set( size_t align, size_t dim, const T fill[] ); §\C{// aligned array[dim], T size elements, fill elements with array}§ 6742 T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ); §\C{// realloc new aligned array[dim], fill new bytes with value}§ 6743 6744 // §\CFA§ safe initialization/copy, i.e., implicit size specification 6745 T * memset( T * dest, char fill );§\indexc{memset}§ 6636 6746 T * memcpy( T * dest, const T * src );§\indexc{memcpy}§ 6637 6747 6638 // §\CFA§ safe initialization/copy array 6639 T * amemset( T dest[], char c, size_t dim );6748 // §\CFA§ safe initialization/copy, i.e., implicit size specification, array types 6749 T * amemset( T dest[], char fill, size_t dim ); 6640 6750 T * amemcpy( T dest[], const T src[], size_t dim ); 6641 6751 } 6642 6752 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 ); } )6753 // §\CFA§ allocation/deallocation and constructor/destructor, non-array types 6754 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );§\indexc{new}§ 6755 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );§\indexc{delete}§ 6756 forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } ) 6647 6757 void delete( T * ptr, Params rest ); 6648 6758 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 ); } )6759 // §\CFA§ allocation/deallocation and constructor/destructor, array types 6760 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§ 6761 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§ 6762 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } ) 6653 6763 void adelete( size_t dim, T arr[], Params rest ); 6654 6764 \end{cfa}
Note:
See TracChangeset
for help on using the changeset viewer.