Changeset 4f0534f
- Timestamp:
- Mar 5, 2020, 1:00:36 PM (5 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
rd870df3 r4f0534f 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 : 38 7613 %% Last Modified On : Thu Mar 5 12:09:42 2020 14 %% Update Count : 3885 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 211 211 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 212 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: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: 215 215 \begin{center} 216 216 \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 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 \\ 222 223 \end{tabular} 223 224 \end{center} … … 512 513 Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism: 513 514 \begin{cfa} 514 int ®` ®otype®`®= 3; §\C{// make keyword an identifier}§515 double ®` ®forall®`®= 3.5;515 int ®``®otype = 3; §\C{// make keyword an identifier}§ 516 double ®``®forall = 3.5; 516 517 \end{cfa} 517 518 … … 524 525 // include file uses the CFA keyword "with". 525 526 #if ! defined( with ) §\C{// nesting ?}§ 526 #define with ®` ®with®`®§\C{// make keyword an identifier}§527 #define with ®``®with §\C{// make keyword an identifier}§ 527 528 #define __CFA_BFD_H__ 528 529 #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}§ 532 531 #if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§ 533 532 #undef with … … 576 575 \section{Exponentiation Operator} 577 576 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$.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$. 580 579 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 580 582 As for \Index{division}, there are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.581 There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types. 583 582 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.583 Overflow for a large exponent or negative exponent returns zero. 585 584 Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative. 586 585 \begin{cfa} … … 589 588 1 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i 590 589 \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.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. 592 591 Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©. 593 592 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available. … … 598 597 OT ?®\®?( OT ep, unsigned long int y ); 599 598 \end{cfa} 600 The user type ©T© must define multiplication, one , ©1©, and,©*©.599 The user type ©T© must define multiplication, one (©1©), and ©*©. 601 600 602 601 … … 626 625 627 626 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 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: 657 634 \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} 638 switch ( i ) { 639 case ®1, 3, 5®: 640 ... 641 case ®2, 4, 6®: 642 ... 643 } 712 644 \end{cfa} 713 645 & 714 646 \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 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 765 662 \end{cfa} 766 663 \end{tabular} 767 664 \end{cquote} 768 \caption{Loop Control Examples} 769 \label{f:LoopControlExamples} 770 \end{figure} 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} 771 679 772 680 … … 977 885 978 886 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 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 906 \end{cfa} 907 & 908 \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 922 \end{cfa} 923 & 924 \begin{cfa} 925 choose ( ... ) { 926 case 3: 927 choose ( ... ) { 928 case 4: 929 for ( ... ) { 930 // multi-level transfer 931 ... ®fallthru common;® 932 } 933 ... 934 } 992 935 ... 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} 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; } 996 1028 \end{cfa} 997 1029 & 998 1030 \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 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 1014 1073 \end{cfa} 1015 1074 \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} 1032 1078 1033 1079 % for () => for ( ;; ) … … 6547 6593 hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}). 6548 6594 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.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. 6550 6596 6551 6597 … … 6561 6607 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 6608 6563 Storage management provides the following capabilities:6609 C storage management provides the following capabilities: 6564 6610 \begin{description} 6565 \item[fill ]6566 after allocation the storage is filled with a specified character.6611 \item[filled] 6612 after allocation with a specified character or value. 6567 6613 \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 .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. 6570 6616 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.6617 \item[align] 6618 an allocation on a specified memory boundary, \eg, an address multiple of 64 or 128 for cache-line purposes. 6573 6619 \item[array] 6574 6620 the allocation size is scaled to the specified number of array elements. 6575 6621 An array may be filled, resized, or aligned. 6576 6622 \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@{}} 6580 6627 \multicolumn{1}{c}{}& & \multicolumn{1}{c|}{fill} & resize & alignment & array \\ 6581 6628 \hline 6582 6629 C & ©malloc© & no & no & no & no \\ 6583 6630 & ©calloc© & yes (0 only) & no & no & yes \\ 6584 & ©realloc© & no/copy& yes & no & no \\6631 & ©realloc© & copy & yes & no & no \\ 6585 6632 & ©memalign© & no & no & yes & no \\ 6633 & ©aligned_alloc© & no & no & yes & no \\ 6586 6634 & ©posix_memalign© & no & no & yes & 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 & 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 \\ 6592 6644 \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}. 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 6595 6654 6596 6655 \leavevmode 6597 6656 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 6598 // C unsafe allocation6599 6657 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 } 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 6610 6673 6611 6674 forall( dtype T | sized(T) ) { 6612 // §\CFA§ safe equivalents, i.e., implicit size specification6675 // §\CFA§ safe equivalents, i.e., implicit size specification 6613 6676 T * malloc( void ); 6614 6677 T * calloc( size_t dim ); 6615 6678 T * realloc( T * ptr, size_t size ); 6616 6679 T * memalign( size_t align ); 6680 T * cmemalign( size_t align, size_t dim ); 6617 6681 T * aligned_alloc( size_t align ); 6618 6682 int posix_memalign( T ** ptr, size_t align ); 6619 6683 6620 // §\CFA§ safe general allocation, fill, resize, array6684 // §\CFA§ safe general allocation, fill, resize, alignment, array 6621 6685 T * alloc( void );§\indexc{alloc}§ 6622 T * alloc( char fill );6623 6686 T * alloc( size_t dim ); 6624 T * alloc( size_t dim, char fill );6625 6687 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}§ 6636 6708 T * memcpy( T * dest, const T * src );§\indexc{memcpy}§ 6637 6709 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 ); 6640 6712 T * amemcpy( T dest[], const T src[], size_t dim ); 6641 6713 } 6642 6714 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 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 ); } ) 6647 6719 void delete( T * ptr, Params rest ); 6648 6720 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 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 ); } ) 6653 6725 void adelete( size_t dim, T arr[], Params rest ); 6654 6726 \end{cfa}
Note: See TracChangeset
for help on using the changeset viewer.