- Timestamp:
- Sep 18, 2015, 10:04:03 AM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 8cbf8cd, ce6c57c
- Parents:
- 971ae89
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/refrat/refrat.tex
r971ae89 r2f9956b 4041 4041 4042 4042 4043 \setcounter{subsection}{2} 4043 \subsection{Labeled statements} 4044 4045 \begin{syntax} 4046 \oldlhs{labeled-statement} 4047 \rhs \lstinline$case$ \nonterm{case-value-list} : \nonterm{statement} 4048 \lhs{case-value-list} 4049 \rhs \nonterm{case-value} 4050 \rhs \nonterm{case-value-list} \lstinline$,$ \nonterm{case-value} 4051 \lhs{case-value} 4052 \rhs \nonterm{constant-expression} 4053 \rhs \nonterm{subrange} 4054 \lhs{subrange} 4055 \rhs \nonterm{constant-expression} \lstinline$~$ \nonterm{constant-expression} 4056 \end{syntax} 4057 4058 The following have identical meaning: 4059 \begin{lstlisting} 4060 case 1:@\ \ @case 2:@\ \ @case 3:@\ \ @case 4:@\ \ @case 5: 4061 case 1, 2, 3, 4, 5: 4062 case 1~5: 4063 \end{lstlisting} 4064 The multiple subranges are allowed: 4065 \begin{lstlisting} 4066 case 1~4, 9~14, 27~32: 4067 \end{lstlisting} 4068 4069 The \lstinline$case$ and \lstinline$default$ clauses are restricted within the \lstinline$switch$ and \lstinline$choose$ statements, precluding Duff's device. 4070 4071 4044 4072 \subsection{Expression and null statements} 4045 4073 … … 4049 4077 \subsection{Selection statements} 4050 4078 4051 The controlling expression \lstinline$E$ in the switch statement 4079 \begin{syntax} 4080 \oldlhs{selection-statement} 4081 \rhs \lstinline$choose$ \lstinline$($ \nonterm{expression} \lstinline$)$ \nonterm{statement} 4082 \end{syntax} 4083 4084 The controlling expression \lstinline$E$ in the \lstinline$switch$ and \lstinline$choose$ statement: 4052 4085 \begin{lstlisting} 4053 4086 switch ( E ) ... 4087 choose ( E ) ... 4054 4088 \end{lstlisting} 4055 4089 may have more than one interpretation, but it shall have only one interpretation with an integral … … 4058 4092 4059 4093 4094 \setcounter{subsubsection}{3} 4095 \subsubsection{The \lstinline$choose$ statement} 4096 4097 The \lstinline$choose$ statement is the same as the \lstinline$switch$ statement except control transfers to the end of the \lstinline$choose$ statement at a \lstinline$case$ or \lstinline$default$ labeled statement. 4098 The \lstinline$fallthru$ statement is used to fall through to the next \lstinline$case$ or \lstinline$default$ labeled statement. 4099 4100 The following have identical meaning: 4101 \begin{flushleft} 4102 \begin{tabular}{@{\hspace{2em}}l@{\hspace{2em}}l@{}} 4103 \begin{lstlisting} 4104 switch (...) { 4105 case 1: ... ; break; 4106 case 2: ... ; break; 4107 case 3: ... ; // fall through 4108 case 4: ... ; // fall through 4109 default: ... break; 4110 } 4111 \end{lstlisting} 4112 & 4113 \begin{lstlisting} 4114 choose (...) { 4115 case 1: ... ; // exit 4116 case 2: ... ; // exit 4117 case 3: ... ; fallthru; 4118 case 4: ... ; fallthru; 4119 default: ... ; // exit 4120 } 4121 \end{lstlisting} 4122 \end{tabular} 4123 \end{flushleft} 4124 The \lstinline$choose$ statement addresses the problem of accidental fall-through associated with \lstinline$switch$ statement. 4125 4126 4060 4127 \subsection{Iteration statements} 4061 4128 … … 4074 4141 is treated as 4075 4142 \begin{lstlisting} 4076 for ( ( void )( a ); ( int )(( b )!=0); ( void )( c ) ) @\ldots@4143 for ( ( void )( a ); ( int )(( b )!=0); ( void )( c ) ) ... 4077 4144 \end{lstlisting} 4078 4145 … … 4080 4147 \subsection{Jump statements} 4081 4148 4082 An expression in a \lstinline$return$ statement is treated as being 4083 cast to the result type of the function. 4149 \begin{syntax} 4150 \oldlhs{jump-statement} 4151 \rhs \lstinline$continue$ \nonterm{identifier}\opt 4152 \rhs \lstinline$break$ \nonterm{identifier}\opt 4153 \end{syntax} 4154 4155 Labeled \lstinline$continue$ and \lstinline$break$ allow useful but restricted control-flow that reduces the need for the \lstinline$goto$ statement for exiting multiple nested control-structures. 4156 \begin{lstlisting} 4157 L1: { // compound 4158 L2: switch ( ... ) { // switch 4159 case ...: 4160 L3: for ( ;; ) { // outer for 4161 L4: for ( ;; ) { // inner for 4162 continue L1; // error: not enclosing iteration 4163 continue L2; // error: not enclosing iteration 4164 continue L3; // next iteration of outer for 4165 continue L4; // next iteration of inner for 4166 break L1; // exit compound 4167 break L2; // exit switch 4168 break L3; // exit outer for 4169 break L4; // exit inner for 4170 } // for 4171 } // for 4172 break; // exit switch 4173 default: 4174 break L1; // exit compound 4175 } // switch 4176 ... 4177 } // compound 4178 \end{lstlisting} 4179 4180 4181 \setcounter{subsubsection}{1} 4182 \subsubsection{The \lstinline$continue$ statement} 4183 4184 The identifier in a \lstinline$continue$ statement shall name a label located on an enclosing iteration statement. 4185 4186 4187 \subsubsection{The \lstinline$break$ statement} 4188 4189 The identifier in a \lstinline$break$ statement shall name a label located on an enclosing compound, selection or iteration statement. 4190 4191 4192 \subsubsection{The \lstinline$return$ statement} 4193 4194 An expression in a \lstinline$return$ statement is treated as being cast to the result type of the 4195 function. 4084 4196 4085 4197
Note: See TracChangeset
for help on using the changeset viewer.