- Timestamp:
- Mar 20, 2026, 8:23:59 AM (33 hours ago)
- Branches:
- master
- Children:
- c6d65a1
- Parents:
- 5c56a22
- Location:
- doc/user
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/Makefile
r5c56a22 r2c2e865 9 9 BibTeX = BIBINPUTS=${BibDir}: && export BIBINPUTS && bibtex 10 10 11 MAKEFLAGS = --no-print-directory --silent #11 MAKEFLAGS = --no-print-directory # --silent 12 12 VPATH = ${Build} ${Figures} 13 13 -
doc/user/user.tex
r5c56a22 r2c2e865 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Wed Sep 17 09:15:48 202514 %% Update Count : 7 25113 %% Last Modified On : Fri Mar 20 08:05:59 2026 14 %% Update Count : 7399 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 153 153 % Any language feature that is not described here can be assumed to be using the standard \Celeven syntax. 154 154 \CFA adds many modern features that directly lead to increased \emph{\Index{safety}} and \emph{\Index{productivity}}, while maintaining interoperability with existing C programs and achieving similar performance. 155 Like C, \CFA is a statically typed, procedural (non-\Index{object-oriented}) language with a low-overhead runtime, meaning there is no global \Index{garbage-collection}, but \Index{regional garbage-collection}\index{garbage-collection!regional} is possible.155 Like C, \CFA is a statically typed, procedural (non-\Index{object-oriented}) language with a low-overhead runtime, meaning there is \Index{managed memory} (no global \Index{garbage-collection}, but \Index{regional garbage-collection}\index{garbage-collection!regional} is possible. 156 156 The primary new features include polymorphic routines and types, exceptions, concurrency, and modules. 157 157 158 158 One of the main design philosophies of \CFA is to ``\Index{describe not prescribe}'', which means \CFA tries to provide a pathway from low-level C programming to high-level \CFA programming, but it does not force programmers to ``do the right thing''. 159 There is no notion or requirement of \emph{rewriting} a legacy C program to \CFA. 159 160 Programmers can cautiously add \CFA extensions to their C programs in any order and at any time to incrementally move towards safer, higher-level programming. 160 A programmer is always free to reach back to C from \CFA, for any reason, and in many cases, new \CFA features can be locally switched back to their C counterpart.161 There is no notion or requirement for \emph{rewriting} a legacy C program to \CFA;162 instead, a programmer evolves a legacy program into \CFA by incrementally incorporating \CFA features.163 As well, new programs can be written in \CFA using a combination of C and \CFA features.164 161 In many ways, \CFA is to C as \Index{Scala}~\cite{Scala} is to Java, providing a vehicle for new typing and control-flow capabilities on top of a highly popular programming language allowing immediate dissemination. 165 162 … … 211 208 The manual does not teach programming, \ie how to combine the new constructs to build complex programs. 212 209 The reader must have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented, as well as some experience programming in C/\CC. 213 Implementers should refer to the \CFA Programming Language Specification for details about the language syntax and semantics.210 % Implementers should refer to the \CFA Programming Language Specification for details about the language syntax and semantics. 214 211 Changes to the syntax and additional features are expected to be included in later revisions. 215 212 … … 321 318 \end{comment} 322 319 323 However, it is necessary to differentiate between C and \CFA code because of name \Index{overload}ing, as for \CC.320 As for \CC, it is necessary to differentiate between C and \CFA code because of name \Index{overload}ing. 324 321 For example, the C math-library provides the following routines for computing the absolute value of the basic types: ©abs©, ©labs©, ©llabs©, ©fabs©, ©fabsf©, ©fabsl©, ©cabsf©, ©cabs©, and ©cabsl©. 325 322 Whereas, \CFA wraps these routines into one overloaded name ©abs©: … … 338 335 The problem is a \Index{name clash} between the C name ©abs© and the \CFA names ©abs©, resulting in two name linkages\index{C linkage}: ©extern "C"© and ©extern "Cforall"© (default). 339 336 Overloaded names must use \newterm{name mangling}\index{mangling!name} to create unique names that are different from unmangled C names. 340 Hence, there is the same need as in \CCto know if a name is a C or \CFA name, so it can be correctly formed.337 Hence, there is the same need, as in \CC, to know if a name is a C or \CFA name, so it can be correctly formed. 341 338 The only way around this problem is C's approach of creating unique names for each pairing of operation and type. 342 339 … … 349 346 \section{\CFA Compilation} 350 347 351 \CFA is a \newterm{transpiler}, meaning it reads in a programming language (\CFA) as input and generates another programming language (C) as output, whereas a \newterm{compiler} reads in a programming language and generates assembler/machine code.352 Hence, \CFA is like the C preprocessor modifying a program and sending it on to another step for further transformation.348 \CFA is currently a \newterm{transpiler}, meaning it reads in a programming language (\CFA) as input and generates another programming language (C) as output, whereas a \newterm{compiler} reads in a programming language and generates assembler/machine code. 349 Hence, \CFA is like the C preprocessor modifying a program and sending it onto another step for further transformation. 353 350 The order of transformation is C preprocessor, \CFA, and finally GNU C compiler, which also has a number of transformation steps, such as assembler and linker. 354 351 … … 359 356 There is no ordering among options (flags) and files, unless an option has an argument, which must appear immediately after the option possibly with or without a space separating option and argument. 360 357 361 \CFA has the following ©gcc© flags turned on:362 \begin{description} [topsep=0pt]358 \CFA turns on the following ©gcc© flags. 359 \begin{description} 363 360 \item 364 361 \Indexc{-std=gnu11}\index{compilation option!-std=gnu11@{©-std=gnu11©}} … … 366 363 \end{description} 367 364 368 \CFA has the following new options: 369 \begin{description}[topsep=0pt] 365 \CFA adds the following new flags, where prefixing with ©"no"© negates the meaning of the flag. 366 \begin{description}[leftmargin=*,itemsep=0pt] 367 \item 368 \Indexc{-help}\index{compilation option!-help@©-help©} 369 Information about the set of \CFA compilation flags is printed. 370 371 \item 372 \Indexc{-nohelp}\index{compilation option!-nohelp@©-nohelp©} 373 Information about the set of \CFA compilation flags is not printed. 374 \textbf{This option is the default.} 375 370 376 \item 371 377 \Indexc{-CFA}\index{compilation option!-CFA@©-CFA©} … … 387 393 \Indexc{-nodebug}\index{compilation option!-nodebug@©-nodebug©} 388 394 The program is linked with the non-debugging version of the runtime system, so the execution of the program is faster. 389 \Emph{However, no runtime checks or ©assert©s are performed so errors usually result in abnormal program behaviour or termination.}390 391 \item392 \Indexc{-help}\index{compilation option!-help@©-help©}393 Information about the set of \CFA compilation flags is printed.394 395 \item396 \Indexc{-nohelp}\index{compilation option!-nohelp@©-nohelp©}397 Information about the set of \CFA compilation flags is not printed.398 \textbf{This option is the default.}399 395 400 396 \item … … 457 453 \end{lstlisting} 458 454 Alternatively, multiple flags can be specified separated with commas and \emph{without} spaces. 459 \begin{lstlisting}[language=sh, {moredelim=**[is][\protect\color{red}]{®}{®}}]455 \begin{lstlisting}[language=sh,escapechar=§,{moredelim=**[is][\protect\color{red}]{®}{®}}] 460 456 cfa §test§.cfa -XCFA®,®-Pparse®,®-n # show program parse without prelude 461 457 \end{lstlisting} … … 504 500 \item 505 501 \Indexc{excpdecl}\index{transpiler option!-P@{©-P©}!©excpdecl©}\index{transpiler option!--print@{©-print©}!©excpdecl©} \, print AST after translating exception decls 506 \item507 \Indexc{symevt}\index{transpiler option!-P@{©-P©}!©symevt©}\index{transpiler option!--print@{©-print©}!©symevt©} \, print AST after symbol table events508 \item509 \Indexc{expralt}\index{transpiler option!-P@{©-P©}!©expralt©}\index{transpiler option!--print@{©-print©}!©expralt©} \, print AST after expressions alternatives510 \item 511 \Indexc{val decl}\index{transpiler option!-P@{©-P©}!©valdecl©}\index{transpiler option!--print@{©-print©}!©valdecl©} \, print AST after declaration validation pass502 % \item 503 % \Indexc{symevt}\index{transpiler option!-P@{©-P©}!©symevt©}\index{transpiler option!--print@{©-print©}!©symevt©} \, print AST after symbol table events 504 % \item 505 % \Indexc{expralt}\index{transpiler option!-P@{©-P©}!©expralt©}\index{transpiler option!--print@{©-print©}!©expralt©} \, print AST after expressions alternatives 506 \item 507 \Indexc{validecl}\index{transpiler option!-P@{©-P©}!©validecl©}\index{transpiler option!--print@{©-print©}!©validecl©} \, print AST after declaration validation pass 512 508 \item 513 509 \Indexc{bresolver}\index{transpiler option!-P@{©-P©}!©bresolver©}\index{transpiler option!--print@{©-print©}!©bresolver©} \, print AST before resolver step 514 510 \item 515 \Indexc{expranl y}\index{transpiler option!-P@{©-P©}!©expranly©}\index{transpiler option!--print@{©-print©}!©expranly©} \, print AST after expression analysis511 \Indexc{expranl}\index{transpiler option!-P@{©-P©}!©expranl©}\index{transpiler option!--print@{©-print©}!©expranl©} \, print AST after expression analysis 516 512 \item 517 513 \Indexc{ctordtor}\index{transpiler option!-P@{©-P©}!©ctordtor©}\index{transpiler option!--print@{©-print©}!©ctordtor©} \, print AST after ctor/dtor are replaced … … 605 601 Exponentiation, $x^y$, means raise $x$ to the $y$th power. 606 602 When $y$ is a positive integer, exponentiation corresponds to $\prod_{i=1}^{y} x$. 607 608 603 C, \CC, Java and other programming languages have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, using a routine like \Indexc{pow( x, y )} instead. 609 604 Ada, Haskell, Python and other programming languages have an exponentiation operator often using operators ©^© or ©**©. … … 645 640 \subsection{\texorpdfstring{\LstKeywordStyle{if} / \LstKeywordStyle{while} Statement}{if / while Statement}} 646 641 647 The \Indexc{if} and \Indexc{while} expressions are extended with declarations, similar to the \Indexc{for} declaration expression. \footnote{648 Declarations in the \Indexc{do}-©while© condition are not useful because they appear after the loop body.} 642 The \Indexc{if} and \Indexc{while} expressions are extended with declarations, similar to the \Indexc{for} declaration expression. 643 Note, declarations in the \Indexc{do}-©while© condition are not useful because they appear after the loop body. 649 644 \begin{cfa} 650 645 if ( ®int x = f()® ) ... §\C[2.75in]{// x != 0}§ … … 755 750 756 751 C allows a number of questionable forms for the \Indexc{switch} statement: 757 \begin{enumerate} 752 \begin{enumerate}[leftmargin=*] 758 753 \item 759 754 By default, the end of a \Indexc{case} clause\footnote{ … … 881 876 The key observation is that the ©switch© statement branches into a control structure, \ie there are multiple entry points into its statement body. 882 877 \end{enumerate} 883 884 878 Before discussing language changes to deal with these problems, it is worth observing that in a typical C program: 885 879 \begin{itemize} … … 893 887 and there is only a medium amount of fall-through from one ©case© clause to the next, and most of these result from a list of case values executing common code, rather than a sequence of case actions that compound. 894 888 \end{itemize} 889 895 890 These observations put into perspective the \CFA changes to the ©switch© statement. 896 \begin{enumerate} 891 \begin{enumerate}[leftmargin=*] 897 892 \item 898 893 Eliminating default fall-through has the greatest potential for affecting existing code. … … 1015 1010 To simplify creating an infinite loop, the \Indexc{for}, \Indexc{while}, and \Indexc{do} loop-predicate\index{loop predicate} is extended with an empty conditional, meaning a comparison value of ©1© (true). 1016 1011 \begin{cfa} 1017 while ( ) §\C{// while ( true )}§ 1018 for ( ) §\C{// for ( ; true; )}§ 1019 do ... while ( ) §\C{// do ... while ( true )}§ 1020 \end{cfa} 1021 1022 Looping a predefined number of times, possibly with a loop index, occurs frequently. 1023 The ©for© control\index{for control}, \ie ©for ( /* control */ )©, is extended with a range and step. 1024 A range is a set of values defined by an optional low value (default to 0), tilde, and high value, ©L ~ H©, with an optional step ©~ S© (default to 1), which means an ascending set of values from ©L© to ©H© in positive steps of ©S©. 1025 \begin{cfa} 1026 0 ~ 5 §\C{// \{ 0, 1, 2, 3, 4, 5 \}}§ 1027 -8 ~ -2 ~ 2 §\C{// \{ -8. -6, -4, -2 \}}§ 1028 -3 ~ 3 ~ 1 §\C{// \{ -3, -2, -1, 0, 1, 2, 3 \}}§ 1029 \end{cfa} 1030 \R{Warning}: A range in descending order, \eg ©5 ~ -3© is the null (empty) set, \ie no values in the set. 1031 As well, a ©0© or negative step is undefined. 1032 1033 The range character, ©'~'©, is decorated on the left and right to control how the set values are presented in the loop body. 1034 The range character can be prefixed with ©'+'© or ©'-'© indicating the \emph{direction} the range is scanned, \ie from left to right (ascending) or right to left (descending). 1035 Ascending uses operator \Indexc{+=}; 1036 descending uses operator \Indexc{-=}. 1037 If there is no prefix character, it defaults to ©'+'©. 1038 \begin{cfa} 1039 -8 ®§\Sp§®~ -2 §\C{// ascending, no prefix}§ 1040 0 ®+®~ 5 §\C{// ascending, prefix}§ 1041 -3 ®-®~ 3 §\C{// descending, prefix}§ 1042 \end{cfa} 1043 For descending iteration, the ©L© and ©H© values are \emph{implicitly} switched, and the increment/decrement for ©S© is toggled. 1044 Hence, the order of values in a set may not be the order the values are presented during looping. 1045 Changing the iteration direction is faster and safer because the direction prefix can be added/removed without changing existing (correct) range information. 1046 \R{Warning}: reversing the range endpoints for descending order results in an empty set. 1047 \begin{cfa} 1048 for ( i; ®10 -~ 1® ) §{\C{// WRONG descending range!}§ 1049 \end{cfa} 1050 1051 Because C uses zero origin, most loops iterate from 0 to $N - 1$. 1052 Hence, when scanning a range during iteration, the last value is dropped, \eg ©0 ~ 5© is ©0, 1, 2, 3, 4©, an exclusive range, [©L©,©H©\R{)}. 1053 To obtain \emph{all} the values in the range, the range character is postfixed with ©'='©, \eg ©0 ~= 5© is ©0, 1, 2, 3, 4, 5©, an inclusive range, [©L©,©H©\R{]}. 1054 \index{\~}\index{ascending exclusive range} 1055 \index{\~=}\index{ascending inclusive range} 1056 \index{-\~}\index{descending exclusive range} 1057 \index{-\~=}\index{descending inclusive range} 1058 1059 \begin{comment} 1060 To simplify loop iteration a range is provided, from low to high, and a traversal direction, ascending (©+©) or descending (©-©). 1061 The following is the syntax for the loop range, where ©[©\,©]© means optional. 1062 \begin{cfa}[deletekeywords=default] 1063 [ ®index ;® ] [ [ ®min® (default 0) ] [ direction ®+®/®-® (default +) ] ®~® [ ®=® (include endpoint) ] ] ®max® [ ®~ increment® ] 1064 \end{cfa} 1065 For ©=©, the range includes the endpoint (©max©/©min©) depending on the direction (©+©/©-©). 1066 \end{comment} 1067 1068 ©for© control is formalized by the following regular expression: 1012 while ( ) §\C{// while ( true )}§ 1013 for ( ) §\C{// for ( ; true; )}§ 1014 do ... while ( ) §\C{// do ... while ( true )}§ 1015 \end{cfa} 1016 1017 The ©for© loop is the primary mechanism for iterating a predefined number of times. 1018 The basic C ©for© loop requires multiple parts, even though most are unnecessary, \eg interating 5 times provides multiple places for errors. 1019 \begin{cfa} 1020 for ( ®int i = 0; i < 5; i += 1® ) ... 1021 \end{cfa} 1022 \CFA simplifies the ©for©-control\index{for control} by defining an integral set of values and specifying if the set is traversed forward or backward. 1023 A range is a set of values defined by an optional low value (0 default) and high value, with an optional step ©S© (1 default) seperated by tildes, ©[L ~] H [~ S]©, where ©[©\,©]© implies optional. 1024 For example, the set ©0 ~ 5 ~ 1© is the set of values 0, 1, 2, 3, 4, 5, which can be travered either direction. 1025 Hence, iterating 5 times can be written succinctly as: 1026 \begin{cfa} 1027 for ( 5 ) ... §\C{// 0 \textasciitilde\ 5 \textasciitilde\ 1}§ 1028 for ( 0 ~ 5 ) ... §\C{// 0 \textasciitilde\ 5 \textasciitilde\ 1}§ 1029 for ( 0 ~ 5 ~ 1 ) ... §\C{// 0 \textasciitilde\ 5 \textasciitilde\ 1}§ 1030 \end{cfa} 1031 To indicate the scanned direction, the middle tilde is prefixed with ©'+'© or ©'-'©, for forward or backwards, respectively; 1032 no prefix character, defaults to ©'+'©, as above. 1033 \begin{cfa} 1034 for ( ®+®~ 5 ) ... §\C{// forward}§ 1035 for ( ®-®~ 5 ) ... §\C{// backward}§ 1036 for ( 0 ®+®~ 5 ) ... §\C{// forward}§ 1037 for ( 0 ®-®~ 5 ) ... §\C{// backward}§ 1038 for ( 0 ®+®~ 5 ~ 1 ) ... §\C{// forward}§ 1039 for ( 0 ®-®~ 5 ~ 1 ) ... §\C{// backward}§ 1040 \end{cfa} 1041 \R{Warning}: the expression ©~5© (no prefix), has a preexisting meaning in C: complement the bits of ©5©, means ©for ( -6 )©, as ©-6© is the complement of ©5©. 1042 This anomaly is unlikely to cause problems because programers should write the shorter ©for ( 5 )©. 1043 Hence, for descending iteration, the ©L© and ©H© values are \emph{implicitly} switched, and the increment/decrement for ©S© is toggled from add to subtract. 1044 Using a direction prefix rather than switching the low and high values is faster and safer because the prefix is added/removed without changing existing (correct) range information. 1045 A consequence of of the direction prefix is that the range, \eg ©5 ~ 0© is the null (empty) set, as there are no values in the range ©5© to ©0©. 1046 As well, a ©0© or negative step generates an infinite or large range (finite integers), as it does in C. 1047 \begin{cfa} 1048 -3 ~ 3 ~ ®0® §\C{// infinite: -3, -3, -3, ... }§ 1049 -3 ~ 3 ~ ®-1® §\C{// large: -3, -4, -5, ..., 2, 3}§ 1050 -3 -~ 3 ~ ®-1® §\C{// large: 3, 4, 5, ..., -2, -3}§ 1051 \end{cfa} 1052 Finally, C uses zero origin, so most loops iterate from 0 to $N - 1$. 1053 To match this idiom, a range used for iteration, drops the last value, \eg ©0 ~ 5© is actually ©0, 1, 2, 3, 4©, \ie an exclusive range, [©L©,©H©\R{)}. 1054 To obtain the inclusive range, [©L©,©H©\R{]}, the middle titlde is postfixed with ©'='©, \eg ©0 ~= 5© is ©0, 1, 2, 3, 4, 5©. 1055 \index{\~}\index{ascending exclusive range}% 1056 \index{\~=}\index{ascending inclusive range}% 1057 \index{-\~}\index{descending exclusive range}% 1058 \index{-\~=}\index{descending inclusive range}% 1059 The following is the complete regular expression for ©for©-control: 1069 1060 \begin{cquote} 1070 1061 [ ©L© ]\ \ [ ©+©\ \ |\ \ ©-© ]\ \ \R{©~©}\ \ [ ©=© ]\ \ ©H©\ \ [ ©~© ©S© ] 1071 1062 \end{cquote} 1072 1063 where ©[©\,©]© denotes optional and ©|© denotes alternative. 1073 That is, the optional low set value, the optional scan direction (ascending/descending), the (possibly) required range character, the optional include last-scan value, the required high set value, and the optional range character and step value. 1074 \R{Warning}: the regular expression allows the form ©~H©, but this syntax has a preexisting meaning in C: complement the bits of ©H©, \eg ©for ( ~5 )© meaning ©for ( -6 )©, as ©-6© is the complement of ©5©. 1075 This anomaly is unlikely to cause problems because programers should write the shorter ©for ( 5 )©. 1076 1077 The previous ©for© loops have an anonymous loop index in which the range iteration is computed. 1078 To access the value of the range iteration in the loop body, a \Index{loop index} is specified before the range. 1079 \begin{cfa} 1080 for ( ®int i;® 0 ~ 10 ~ 2 ) { ... ®i® ... } §\C{// loop index available in loop body}§ 1081 \end{cfa} 1082 Hence, unlike the 3 components in the C ©for©-control, there are only two components in the \CFA ©for©-control: the optional index variable and the range. 1083 The index type is optional (like \CC ©auto©), where the type is normally inferred from the low value ©L© because it initializes the index (the type of ©H© can be different from ©L©). 1084 When ©L© is omitted, the type of the required high value ©H© is used, as both ©L© and ©H© are the same type in this case. 1064 %That is, the optional low set value, the optional scan direction (ascending/descending), the (possibly) required range character, the optional include last-scan value, the required high set value, and the optional range character and step value. 1065 1066 To add a \Index{loop index}, the ©for©-control is prefixed with a variable or variable declaration. 1067 \begin{cfa} 1068 for ( ®i;® ®0L® ~ 10 ~ 2 ) { ... ®i® ... } §\C{// implicitly typed index, typeof(0L) is long int}§ 1069 for ( ®long int i;® 0 ~ 10 ~ 2 ) { ... ®i® ... } §\C{// explicitly typed index}§ 1070 \end{cfa} 1071 Hence, there are only two components in the \CFA ©for©-control \vs 3 in C. 1072 If the index is untyped, it is inferred from the low value ©L© because it initializes the index (the type of ©H© can be different from ©L©). 1073 When ©L© is omitted, the type of ©H© is used, as both ©L© and ©H© are the same type in this case. 1085 1074 \begin{cfa} 1086 1075 for ( i; ®1.5® ~ 5 ) §\C{// typeof(1.5) i; 1.5 is low value}§ 1087 1076 for ( i; ®5.5® ) §\C{// typeof(5.5) i; 5.5 is high value}§ 1088 1077 \end{cfa} 1089 1078 This semantics is the same as \CC ©auto© for declaring the loop index. 1079 \begin{C++} 1080 for ( auto i = 0; i < 1.5; i += 5 ) 1081 \end{C++} 1082 1083 \begin{comment} 1090 1084 The following examples illustrate common \CFA ©for©-control combinations, with the C counter-part in the comment. 1091 1085 \begin{itemize}[itemsep=0pt] … … 1121 1115 \end{cfa} 1122 1116 \end{itemize} 1123 1124 There are situations when the ©for©-control actions need to be moved into the loop body, \eg a mid-loop exit does not need an iteration-completion test in the ©for© control. 1125 The character ©'@'© indicates that a specific ©for©-control action is ignored, \ie generates no code. 1117 \end{comment} 1118 1119 There are also situations when the ©for©-control actions need to be moved into the loop body, \eg a mid-loop exit does not need an iteration-completion test in the ©for©-control. 1120 The character ©'@'© indicates a specific ©for©-control action is elided, \ie generates no code. 1126 1121 \begin{cfa} 1127 1122 for ( i; ®@® -~ 10 ) §\C{// for ( typeof(10) i = 10; \R{/*empty*/}; i -= 1 )}§ … … 1131 1126 \end{cfa} 1132 1127 \R{Warning}: ©L© \emph{cannot} be elided for the ascending range, \lstinline{@ ~ 5}, nor ©H© for the descending range, \lstinline{1 -~ @}, as the loop index is uninitialized. 1133 \R{Warning}:©H© \emph{cannot} be elided in an anonymous loop index, ©1 ~ @©, as there is no index to stop the loop.1128 As well, ©H© \emph{cannot} be elided in an anonymous loop index, ©1 ~ @©, as there is no index to stop the loop. 1134 1129 1135 1130 There are situations when multiple loop indexes are required. 1136 The character ©':'© means add another index, where any number of indices may be chained in a single ©for©control.1131 The character ©':'© is used to add another index, where any number of indices may be chained in a single ©for©-control. 1137 1132 \begin{cfa} 1138 1133 for ( i; 5 ®:® j; 2 ~ 12 ~ 3 ) §\C{// for ( typeof(i) i = 1, j = 2; \R{i < 5 \&\& j < 12}; i += 1, j += 3 )}§ … … 1246 1241 \end{figure} 1247 1242 1248 Finally, any type that satisfies the ©Iterate© trait can be used with ©for© control.1243 Finally, any type that satisfies the ©Iterate© trait can be used with ©for©-control. 1249 1244 \begin{cfa} 1250 1245 forall( T ) trait Iterate { … … 1260 1255 } 1261 1256 \end{cfa} 1262 \VRef[Figure]{f:ForControlStructureType} shows an example of a structure using ©for© control.1257 \VRef[Figure]{f:ForControlStructureType} shows an example of a structure using ©for©-control. 1263 1258 Note, the use of ©(S){0}© when implicitly setting the loop-index type, because using 0 incorrect declares the index to ©int© rather than ©S©. 1264 1259 … … 1490 1485 \end{cfa} 1491 1486 Repeated aggregate qualification is tedious and makes code difficult to read. 1492 Therefore, reducing aggregate qualification is a useful languagedesign goal.1487 Therefore, reducing aggregate qualification is a useful design goal. 1493 1488 1494 1489 C partially addresses the problem by eliminating qualification for enumerated types and unnamed \emph{nested} aggregates, which open their scope into the containing aggregate. … … 1496 1491 \begin{cfa} 1497 1492 struct S { 1498 struct §\R{\LstCommentStyle{/* unnamed */}}§{ int g, h; } __attribute__(( aligned(64) ));1493 struct ®/* unnamed */® { int g, h; } __attribute__(( aligned(64) )); 1499 1494 int tag; 1500 union §\R{\LstCommentStyle{/* unnamed */}}§{1495 union ®/* unnamed */® { 1501 1496 struct { char c1, c2; } __attribute__(( aligned(128) )); 1502 1497 struct { int i1, i2; };
Note:
See TracChangeset
for help on using the changeset viewer.