Changeset 3be81a4 for doc/user


Ignore:
Timestamp:
Jul 11, 2024, 7:32:44 AM (7 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
358e3481
Parents:
9d5eacb
Message:

corrections, update loop control

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r9d5eacb r3be81a4  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Tue Apr 23 14:13:10 2024
    14 %% Update Count     : 6623
     13%% Last Modified On : Tue Jul  9 10:43:40 2024
     14%% Update Count     : 6887
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    182182&
    183183\begin{cfa}[tabsize=3]
    184 #include <fstream>§\indexc{fstream
     184#include <fstream.hfa>§\indexc{fstream.hfa
    185185
    186186int main( void ) {
     
    445445#include <stdio.h>§\indexc{stdio.h}§ §\C{// C header file}§
    446446#else
    447 #include <fstream>§\indexc{fstream}§ §\C{// \CFA header file}§
     447#include <fstream.hfa>§\indexc{fstream.hfa}§ §\C{// \CFA header file}§
    448448#endif
    449449\end{cfa}
     
    10061006\subsection{Loop Control}
    10071007
    1008 Looping a fixed number of times, possibly with a loop index, occurs frequently.
    1009 \CFA condenses simply looping to facilitate coding speed and safety~\see{examples in \VRef[Figure]{f:LoopControlExamples}}.
    1010 
    1011 The \Indexc{for}, \Indexc{while}, and \Indexc{do} loop-control are extended to allow an empty conditional, which implies a comparison value of ©1© (true).
     1008Looping a predefined number of times, possibly with a loop index, occurs frequently.
     1009\CFA condenses writing loops to facilitate coding speed and safety.
     1010
     1011\Indexc{for}, \Indexc{while}, and \Indexc{do} loop-control\index{loop control} are extended with an empty conditional, meaning a comparison value of ©1© (true).
    10121012\begin{cfa}
    10131013while ( ®/* empty */®  )                                §\C{// while ( true )}§
     
    10151015do ... while ( ®/* empty */®  )                 §\C{// do ... while ( true )}§
    10161016\end{cfa}
     1017
     1018The ©for© control\index{for control}, \ie ©for ( /* control */ )©, is extended with a range and step.
     1019A 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©.
     1020\begin{cfa}
     10210 ~ 5                                                                   §\C{// \{ 0, 1, 2, 3, 4, 5 \}}§
     1022-8 ~ -2 ~ 2                                                             §\C{// \{ -8. -6, -4, -2 \}}§
     1023-3 ~ 3 ~ 1                                                              §\C{// \{ -3, -2, -1, 0, 1, 2, 3 \}}§
     1024\end{cfa}
     1025\R{Warning}: A range in descending order, \eg ©5 ~ -3© is the null (empty) set, \ie no values in the set.
     1026\R{Warning}: A ©0© or negative step is undefined.
     1027Note, the order of values in a set may not be the order the values are presented during looping.
     1028
     1029The range character, ©'~'©, is decorated on the left and right to control how the set values are presented in the loop body.
     1030The 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).
     1031Ascending stepping uses operator \Indexc{+=};
     1032descending stepping uses operator \Indexc{-=}.
     1033If there is no prefix character, it defaults to ©'+'©.
     1034\begin{cfa}
     1035-8 ®§\Sp§®~ -2                                                  §\C{// ascending, no prefix}§
     10360 ®+®~ 5                                                                §\C{// ascending, prefix}§
     1037-3 ®-®~ 3                                                               §\C{// descending}§
     1038\end{cfa}
     1039For descending iteration, the ©L© and ©H© values are \emph{implicitly} switched, and the increment/decrement for ©S© is toggled.
     1040When changing the iteration direction, this form is faster and safer, \ie the direction prefix can be added/removed without changing existing (correct) program text.
     1041\R{Warning}: reversing the range endpoints for descending order results in an empty set.
     1042\begin{cfa}
     1043for ( i; ®10 -~ 1® )                                    §{\C{// WRONG descending range!}§
     1044\end{cfa}
     1045
     1046Because C uses zero origin, most loops iterate from 0 to $N - 1$.
     1047Hence, 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{)}.
     1048To 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{]}.
     1049\index{\~}\index{ascending exclusive range}
     1050\index{\~=}\index{ascending inclusive range}
     1051\index{-\~}\index{descending exclusive range}
     1052\index{-\~=}\index{descending inclusive range}
     1053
     1054©for© control is formalized by the following regular expression:
     1055\begin{cquote}
     1056[ ©L© ]\ \ [ ©+©\ \ |\ \ ©-© ]\ \ \R{©~©}\ \ [ ©=© ]\ \ ©H©\ \ [ ©~© ©S© ]
     1057\end{cquote}
     1058where ©[©\,©]© denotes optional and ©|© denotes alternative.
     1059That 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.
     1060\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©.
     1061This anomaly is unlikely to cause problems because programers will write the shorter ©for ( 5 )©.
     1062
     1063The previous ©for© loops have an anonymous loop index in which the range iteration is computed.
     1064To access the value of the range iteration in the loop body, a \Index{loop index} is specified before the range.
     1065\begin{cfa}
     1066for ( ®int i;® 0 ~ 10 ~ 2 ) { ... ®i® ... }     §\C{// loop index available in loop body}§
     1067\end{cfa}
     1068Hence, 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.
     1069The 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©).
     1070When ©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.
     1071\begin{cfa}
     1072for ( i; ®1.5® ~ 5 )                                    §\C{// typeof(1.5) i; 1.5 is low value}§
     1073for ( i; ®5.5® )                                                §\C{// typeof(5.5) i; 5.5 is high value}§
     1074\end{cfa}
     1075
     1076The following examples illustrate common \CFA ©for©-control combinations, with the C counter-part in the comment.
     1077\begin{itemize}[itemsep=0pt]
     1078\item
     1079©H© is implicit ascending exclusive range [0,©H©\R{)}.
     1080\begin{cfa}
     1081for ( ®5® )                                                             §\C{// for ( typeof(5) i; i < 5; i += 1 )}§
     1082\end{cfa}
     1083\item
     1084©~=© ©H© is implicit ascending inclusive range [0,©H©\R{]}.
     1085\begin{cfa}
     1086for ( ®~=® 5 )                                                  §\C{// for ( typeof(5) i; i <= 5; i += 1 )}§
     1087\end{cfa}
     1088\item
     1089©L© ©~©\index{~@©~©} ©H© is explicit ascending exclusive range [©L©,©H©\R{)}.
     1090\begin{cfa}
     1091for ( 1 ®~® 5 )                                                 §\C{// for ( typeof(1) i = 1; i < 5; i += 1 )}§
     1092\end{cfa}
     1093\item
     1094©L© ©~=©\index{~=@©~=©} ©H© is explicit ascending inclusive range [©L©,©H©\R{]}.
     1095\begin{cfa}
     1096for ( 1 ®~=® 5 )                                                §\C{// for ( typeof(1) i = 1; i <= 5; i += 1 )}§
     1097\end{cfa}
     1098\item
     1099©L© ©-~©\index{-~@©-~©} ©H© is explicit descending exclusive range \R{(}©H©,©L©], where ©L© and ©H© are implicitly interchanged to make the range descending.
     1100\begin{cfa}
     1101for ( 1 ®-~® 5 )                                                §\C{// for ( typeof(1) i = 5; i > 0; i -= 1 )}§
     1102\end{cfa}
     1103\item
     1104©L© ©-~=©\index{-~=@©-~=©} ©H© is explicit descending inclusive range \R{[}©H©,©L©], where ©L© and ©H© are implicitly interchanged to make the range descending.
     1105\begin{cfa}
     1106for ( 1 ®-~=® 5 )                                               §\C{// for ( typeof(1) i = 5; i >= 0; i -= 1 )}§
     1107\end{cfa}
     1108\end{itemize}
     1109
     1110There 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.
     1111The character ©'@'© indicates that a specific ©for©-control action is ignored, \ie generates no code.
     1112\begin{cfa}
     1113for ( i; ®@® -~ 10 )                                    §\C{// for ( typeof(10) i = 10; \R{/*empty*/}; i -= 1 )}§
     1114for ( i; 1 ~ ®@® ~ 2 )                                  §\C{// for ( typeof(1) i = 1; \R{/* empty */}; i += 2 )}§
     1115for ( i; 1 ~ 10 ~ ®@® )                                 §\C{// for ( typeof(1) i = 1; i < 10; \R{/* empty */} )}§
     1116for ( i; 1 ~ ®@® ~ ®@® )                                §\C{// for ( typeof(1) i = 1; \R{/* empty */}; \R{/* empty */} )}§
     1117\end{cfa}
     1118\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.
     1119\R{Warning}: ©H© \emph{cannot} be elided in an anonymous loop index, ©1 ~ @©, as there is no index to stop the loop.
     1120
     1121There are situations when multiple loop indexes are required.
     1122The character ©':'© means add another index, where any number of indices may be chained in a single ©for© control.
     1123\begin{cfa}
     1124for ( i; 5  ®:®  j; 2 ~ 12 ~ 3 )                §\C{// for ( typeof(i) i = 1, j = 2; \R{i < 5 \&\& j < 12}; i += 1, j += 3 )}§
     1125for ( i; 5  ®:®  j; 2 ~ @ ~ 3 )                 §\C{// for ( typeof(i) i = 1, j = 2; \R{i < 5}; i += 1, j += 3 )}§
     1126for ( i; 5  ®:®  j; 2.5 ~ @ ~ 3.5 )             §\C{// no C equivalent, without hoisting declaration of floating-point j}§
     1127\end{cfa}
     1128\VRef[Figure]{f:LoopControlExamples} shows more complex loop-control examples across all the different options.
    10171129
    10181130\begin{figure}
     
    10251137for () { sout | "empty"; break; }                               §\C[3in]{sout | nl | nlOff;}§
    10261138
    1027 for ( 0 ) { sout | "A"; } sout | "zero";                §\C{sout | nl;}§
     1139for ( 0 ) { sout | "A"; }                                               §\C{sout | nl;}§
    10281140for ( 1 ) { sout | "A"; }                                               §\C{sout | nl;}§
    10291141for ( 10 ) { sout | "A"; }                                              §\C{sout | nl;}§
     
    10731185empty
    10741186
    1075 zero
     1187
    10761188A
    10771189A A A A A A A A A A
     
    11201232\end{figure}
    11211233
    1122 % for ()  => for ( ;; )
    1123 % for ( 10 - t ) => for ( typeof(10 - t) ? = 0 ; ? < 10 - t; ? += 1 ) // using 0 and 1
    1124 % for ( i ; 10 - t ) => for ( typeof(10 - t) i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1
    1125 % for ( T i ; 10 - t ) => for ( T i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1
    1126 % for ( 3~9 ) => for ( int ? = 3 ; ? < 9; ? += 1 ) // using 1
    1127 % for ( i ; 3~9 ) => for ( int i = 3 ; i < 9; i += 1 ) // using 1
    1128 % for ( T i ; 3~9 ) => for ( T i = 3 ; i < 9; i += 1 ) // using 1
    1129 
    1130 The ©for© control is extended with 4 new loop-control operators, which are not overloadable:
    1131 \begin{description}[itemsep=0pt,parsep=0pt]
    1132 \item
    1133 \Indexc{\~} (tilde) \Index{up-to exclusive range},
    1134 \item
    1135 \Indexc{\~=} (tilde equal) \Index{up-to inclusive range},
    1136 \item
    1137 \Indexc{-\~} (minus tilde) \Index{down-to exclusive range},
    1138 \item
    1139 \Indexc{-\~=} (minus tilde equal) \Index{down-to inclusive range}.
    1140 \end{description}
    1141 
    1142 The ©for© index components, low (L), high (H), and increment (I), are optional.
    1143 If missing:
    1144 \begin{itemize}[itemsep=0pt,parsep=0pt]
    1145 \item
    1146 \Indexc{0} is the implicit low value.
    1147 \item
    1148 \Indexc{1} is the implicit increment value.
    1149 \item
    1150 The up-to range uses operator \Indexc{+=} for increment.
    1151 \item
    1152 The down-to range uses operator \Indexc{-=} for decrement.
    1153 \end{itemize}
    1154 
    1155 If no type is specified for the loop index, it is the type of the high value H (when the low value is implicit) or the low value L.
    1156 \begin{cfa}
    1157 for ( ®5® )                                                             §\C{// typeof(5) anonymous-index; 5 is high value}§
    1158 for ( i; ®1.5® ~ 5.5 )                                  §\C{// typeof(1.5) i; 1.5 is low value}§
    1159 for ( ®int i®; 0 ~ 10 ~ 2 )                             §\C{// int i; type is explicit}§
    1160 \end{cfa}
    1161 
    1162 The following are examples for constructing different for-control:
    1163 \begin{itemize}[itemsep=0pt]
    1164 \item
    1165 H is implicit up-to exclusive range [0,H\R{)}.
    1166 \begin{cfa}
    1167 for ( ®5® )                                                             §\C{// for ( typeof(5) i; i < 5; i += 1 )}§
    1168 \end{cfa}
    1169 \item
    1170 ©~=© H is implicit up-to inclusive range [0,H\R{]}.
    1171 \begin{cfa}
    1172 for ( ®~=® 5 )                                                  §\C{// for ( typeof(5) i; i <= 5; i += 1 )}§
    1173 \end{cfa}
    1174 \item
    1175 L ©~©\index{~@©~©} H is explicit up-to exclusive range [L,H\R{)}.
    1176 \begin{cfa}
    1177 for ( 1 ®~® 5 )                                                 §\C{// for ( typeof(1) i = 1; i < 5; i += 1 )}§
    1178 \end{cfa}
    1179 \item
    1180 L ©~=©\index{~=@©~=©} H is explicit up-to inclusive range [L,H\R{]}.
    1181 \begin{cfa}
    1182 for ( 1 ®~=® 5 )                                                §\C{// for ( typeof(1) i = 1; i <= 5; i += 1 )}§
    1183 \end{cfa}
    1184 \item
    1185 L ©-~©\index{-~@©-~©} H is explicit down-to exclusive range [H,L\R{)}, where L and H are implicitly interchanged to make the range down-to.
    1186 \begin{cfa}
    1187 for ( 1 ®-~® 5 )                                                §\C{// for ( typeof(1) i = 5; i > 0; i -= 1 )}§
    1188 \end{cfa}
    1189 \item
    1190 L ©-~=©\index{-~=@©-~=©} H is explicit down-to inclusive range [H,L\R{]}, where L and H are implicitly interchanged to make the range down-to.
    1191 \begin{cfa}
    1192 for ( 1 ®-~=® 5 )                                               §\C{// for ( typeof(1) i = 5; i >= 0; i -= 1 )}§
    1193 \end{cfa}
    1194 \item
    1195 ©@© means put nothing in this field.
    1196 \begin{cfa}
    1197 for ( i; 1 ~ ®@® ~ 2 )                                  §\C{// for ( typeof(1) i = 1; \R{/* empty */}; i += 2 )}§
    1198 for ( i; 1 ~ 10 ~ ®@® )                                 §\C{// for ( typeof(1) i = 1; i < 10; \R{/* empty */} )}§
    1199 for ( i; 1 ~ ®@® ~ ®@® )                                §\C{// for ( typeof(1) i = 1; /*empty*/; \R{/* empty */} )}§
    1200 \end{cfa}
    1201 L cannot be elided for the up-to range, \lstinline{@ ~ 5}, and H for the down-to range, \lstinline{1 -~ @}, because then the loop index is uninitialized.
    1202 Similarly, the high value cannot be elided is an anonymous loop index (©1 ~ @©), as there is no index to stop the loop.
    1203 \item
    1204 ©:© means add another index.
    1205 \begin{cfa}
    1206 for ( i; 5 ®:® j; 2 ~ 12 ~ 3 )                  §\C{// for ( typeof(i) i = 1, j = 2; i < 5 \&\& j < 12; i += 1, j += 3 )}§
    1207 \end{cfa}
    1208 \end{itemize}
    1209 \R{Warning}: specifying the down-to range maybe unexpected because the loop control \emph{implicitly} switches the L and H values (and toggles the increment/decrement for I):
    1210 \begin{cfa}
    1211 for ( i; 1 ~ 10 )                                               §{\C{// up range}§
    1212 for ( i; 1 -~ 10 )                                              §{\C{// down range}§
    1213 for ( i; ®10 -~ 1® )                                    §{\C{// \R{WRONG down range!}}}§
    1214 \end{cfa}
    1215 The reason for this semantics is that the range direction can be toggled by adding/removing the minus, ©'-'©, versus interchanging the L and H expressions, which has a greater chance of introducing errors.
    1216 
    1217 
    1218 %\subsection{\texorpdfstring{Labelled \protect\lstinline{continue} / \protect\lstinline{break}}{Labelled continue / break}}
    1219 \subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}}
    1220 
    1221 C \Indexc{continue} and \Indexc{break} statements are restricted to one level of nesting for a particular control structure.
    1222 This restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    1223 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@©break©!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}, as in Java.
    1224 For both ©continue© and ©break©, the target label must be directly associated with a \Indexc{for}, \Indexc{while} or \Indexc{do} statement;
    1225 for ©break©, the target label can also be associated with a \Indexc{switch}, \Indexc{if} or compound (©{}©) statement.
    1226 \VRef[Figure]{f:MultiLevelExit} shows a comparison between labelled ©continue© and ©break© and the corresponding C equivalent using ©goto© and labels.
    1227 The innermost loop has 8 exit points, which cause continuation or termination of one or more of the 7 \Index{nested control-structure}s.
     1234Finally, any type that satisfies the ©Iterate© trait can be used with ©for© control.
     1235\begin{cfa}
     1236forall( T ) trait Iterate {
     1237        void ?{}( T & t, zero_t );
     1238        int ?<?( T t1, T t2 );
     1239        int ?<=?( T t1, T t2 );
     1240        int ?>?( T t1, T t2 );
     1241        int ?>=?( T t1, T t2 );
     1242        T ?+=?( T & t1, T t2 );
     1243        T ?+=?( T & t, one_t );
     1244        T ?-=?( T & t1, T t2 );
     1245        T ?-=?( T & t, one_t );
     1246}
     1247\end{cfa}
     1248\VRef[Figure]{f:ForControlStructureType} shows an example of a structure using ©for© control.
     1249Note, the use of ©(S){0}© when implicitly setting the loop-index type, because using 0 incorrect declares the index to ©int© rather than ©S©.
     1250
     1251\begin{figure}
     1252\begin{tabular}{@{}l@{\hspace{5pt}}l@{}}
     1253\begin{cfa}
     1254struct S { int i, j; };
     1255void ?{}( S & s, int i = 0, int j = 0 ) { s.[i, j] = [i, j]; }
     1256void ?{}( S & s, zero_t ) { s.[i, j] = 0; }
     1257int ?<?( S t1, S t2 ) { return t1.i < t2.i && t1.j < t2.j; }
     1258int ?<=?( S t1, S t2 ) { return t1.i <= t2.i && t1.j <= t2.j; }
     1259int ?>?( S t1, S t2 ) { return t1.i > t2.i && t1.j > t2.j; }
     1260int ?>=?( S t1, S t2 ) { return t1.i >= t2.i && t1.j >= t2.j; }
     1261S ?+=?( S & t1, S t2 ) { t1.i += t2.i; t1.j += t2.j; return t1; }
     1262S ?+=?( S & t, one_t ) { t.i += 1; t.j += 1; return t; }
     1263S ?-=?( S & t1, S t2 ) { t1.i -= t2.i; t1.j -= t2.j; return t1; }
     1264S ?-=?( S & t, one_t ) { t.i -= 1; t.j -= 1; return t; }
     1265ofstream & ?|?( ofstream & os, S s ) {
     1266        return os | "(" | s.i | s.j | ")";
     1267}
     1268void & ?|?( ofstream & os, S s ) {
     1269        (ofstream &)(os | s); ends( os );
     1270}
     1271
     1272
     1273
     1274\end{cfa}
     1275&
     1276\begin{cfa}
     1277int main() {
     1278        for ( S i = 0; i < (S){10,10}; i += 1 ) { sout | i; } sout | "A" | nl; // C
     1279        for ( S i; 0 ~ (S){10,10} ) { sout | i; } sout | "B" | nl; // CFA
     1280        for ( i; (S){10,10} ) { sout | i; } sout | "C" | nl;
     1281        for ( i; (S){0} ~ (S){10,10} ) { sout | i; } sout | "D" | nl;
     1282        for ( i; (S){0} ~= (S){10,10} ) { sout | i; } sout | "E" | nl;
     1283        for ( i; (S){0} ~= (S){10,10} ~ (S){2} ) { sout | i; } sout | "F" | nl;
     1284        for ( i; (S){0} -~  (S){10,10} ) { sout | i; } sout | "G" | nl;
     1285        for ( i; (S){0} -~= (S){10,10} ) { sout | i; } sout | "H" | nl;
     1286        for ( i; (S){0} -~= (S){10,10} ~ (S){2,1} ) { sout | i; } sout | "I" | nl;
     1287}
     1288(0 0) (1 1) (2 2) (3 3) (4 4) (5 5) (6 6) (7 7) (8 8) (9 9) A
     1289(0 0) (1 1) (2 2) (3 3) (4 4) (5 5) (6 6) (7 7) (8 8) (9 9) B
     1290(0 0) (1 1) (2 2) (3 3) (4 4) (5 5) (6 6) (7 7) (8 8) (9 9) C
     1291(0 0) (1 1) (2 2) (3 3) (4 4) (5 5) (6 6) (7 7) (8 8) (9 9) D
     1292(0 0) (1 1) (2 2) (3 3) (4 4) (5 5) (6 6) (7 7) (8 8) (9 9) (10 10) E
     1293(0 0) (2 0) (4 0) (6 0) (8 0) (10 0) F
     1294(10 10) (9 9) (8 8) (7 7) (6 6) (5 5) (4 4) (3 3) (2 2) (1 1) G
     1295(10 10) (9 9) (8 8) (7 7) (6 6) (5 5) (4 4) (3 3) (2 2) (1 1) (0 0) H
     1296(10 10) (8 9) (6 8) (4 7) (2 6) (0 5) I
     1297\end{cfa}
     1298\end{tabular}
     1299\caption{For Control with Structure Type}
     1300\label{f:ForControlStructureType}
     1301\end{figure}
     1302
    12281303
    12291304\begin{figure}
     
    12971372\end{figure}
    12981373
     1374
     1375%\subsection{\texorpdfstring{Labelled \protect\lstinline{continue} / \protect\lstinline{break}}{Labelled continue / break}}
     1376\subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}}
     1377
     1378C \Indexc{continue} and \Indexc{break} statements are restricted to one level of nesting for a particular control structure.
     1379This restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
     1380To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@©break©!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}, as in Java.
     1381For both ©continue© and ©break©, the target label must be directly associated with a \Indexc{for}, \Indexc{while} or \Indexc{do} statement;
     1382for ©break©, the target label can also be associated with a \Indexc{switch}, \Indexc{if} or compound (©{}©) statement.
     1383\VRef[Figure]{f:MultiLevelExit} shows a comparison between labelled ©continue© and ©break© and the corresponding C equivalent using ©goto© and labels.
     1384The innermost loop has 8 exit points, which cause continuation or termination of one or more of the 7 \Index{nested control-structure}s.
     1385
    12991386Both labelled \Indexc{continue} and \Indexc{break} are a \Indexc{goto}\index{goto@©goto©!restricted} restricted in the following ways:
    13001387\begin{itemize}
     
    31033190Similarly, if the argument is an expression, it must be parenthesized, \eg ©(i + 3)`h©, or only the last operand of the expression is the argument, \eg ©i + (3`h)©.
    31043191
    3105 \VRef[Figure]{f:UnitsComparison} shows a common usage for postfix functions: converting basic literals into user literals.
     3192\VRef[Figure]{f:UnitsComparison} shows a common example for postfix functions: converting basic literals into user literals.
    31063193\see*{\VRef{s:DynamicStorageManagement} for other uses for postfix functions.}
    3107 The \CFA example (left) stores a mass in units of stones (1 stone = 14 lb or 6.35 kg) and provides an addition operator (imagine a full set of arithmetic operators).
     3194The \CFA example (left) stores a mass in units of stones (1 stone = 14 lb or 6.35 kg) and provides an addition operator ©?+?© (imagine a full set of arithmetic operators).
     3195The arithmetic operators manipulate stones and the postfix operations convert to/from different units.
    31083196The three postfixing function names ©st©, ©lb©, and ©kg©, represent units stones, pounds, and kilograms, respectively.
    31093197Each name has two forms that bidirectional convert: a value of a specified unit to stones, \eg ©w = 14`lb© $\Rightarrow$ ©w == 1© stone or a ©Weight© from stones back to specific units, \eg ©w`lb© (1 stone) to ©14©.
    3110 All arithmetic operations manipulate stones and the postfix operations convert to the different units.
    31113198A similar group of postfix functions provide user constants for converting time units into nanoseconds, which is the basic time unit, \eg ©ns©, ©us©, ©ms©, ©s©, ©m©, ©h©, ©d©, and ©w©, for nanosecond, microsecond, millisecond, second, minute, hour, day, and week, respectively.
    31123199(Note, month is not a fixed period of time nor is year because of leap years.)
     
    32093296
    32103297The \CC example (right) provides a \emph{restricted} capability via user literals.
    3211 The \lstinline[language=C++]{operator ""} only takes a constant argument (\ie no variable argument), and the constant type must be the highest-level constant-type, \eg ©long double© for all floating-point constants.
     3298The \lstinline[language=C++]{operator""} only takes a constant argument (\ie no variable as an argument), and the constant type must be the highest-level constant-type, \eg ©long double© for all floating-point constants.
    32123299As well, there is no constant conversion, \ie ©int© to ©double© constants, so integral constants are handled by a separate set of routines, with maximal integral type ©unsigned long long int©.
    3213 Finally, there is no mechanism to use this syntax for a bidirectional conversion because \lstinline[language=C++]{operator ""} does not accept variable arguments.
     3300Finally, there is no mechanism to use this syntax for a bidirectional conversion because \lstinline[language=C++]{operator""} only accepts a constant argument.
    32143301
    32153302
     
    50695156
    50705157\begin{comment}
    5071 #include <fstream>
     5158#include <fstream.hfa>
    50725159#include <string.h>                                                                             // strcpy
    50735160
     
    63306417\begin{figure}
    63316418\begin{cfa}
    6332 #include <fstream>
     6419#include <fstream.hfa>
    63336420#include <kernel>
    63346421#include <stdlib>
     
    98269913A contrary analysis:  https://hackaday.com/2024/02/29/the-white-house-memory-safety-appeal-is-a-security-red-herring/
    98279914
     9915
     9916From: Ian Fox <ianfox97@gmail.com>
     9917Date: Fri, 10 May 2024 22:11:41 +0200
     9918Subject: Article on C and memory safety
     9919To: pabuhr@uwaterloo.ca
     9920
     9921Hi Dr. Buhr!
     9922
     9923I came across this
     9924<https://crashoverride.com/blog/c-isnt-a-hangover-rust-isnt-a-hangover-cure>
     9925article the other day which I thought made some excellent points, and it
     9926reminded me of your C forall project (especially with regards to the part
     9927about being able to opt in incrementally to the safety features while
     9928rewriting a codebase) so I figured you might enjoy it if you hadn't seen it
     9929already.
     9930
     9931All the best!
     9932Ian
     9933
    98289934% Local Variables: %
    98299935% tab-width: 4 %
Note: See TracChangeset for help on using the changeset viewer.