|
1 | 1 | \clause{Counted loops}
|
2 | 2 | \sclause{Introduction}
|
| 3 | +\pnum |
3 | 4 | A
|
4 | 5 | \defn{counted loop}
|
5 | 6 | is a
|
|
15 | 16 | the loop's iteration count can be computed
|
16 | 17 | before the loop body is executed.
|
17 | 18 |
|
| 19 | +\pnum |
18 | 20 | There shall be no
|
19 | 21 | \tcode{return},
|
20 | 22 | \tcode{break},
|
|
25 | 27 |
|
26 | 28 | \sclause{Constraints on a counted \tcode{for} statement}
|
27 | 29 | \ssclause{Introduction}
|
| 30 | + |
| 31 | +\pnum |
28 | 32 | The syntax of a
|
29 | 33 | \tcode{for}
|
30 | 34 | statement includes three
|
|
36 | 40 | the third is called the
|
37 | 41 | \defn{loop-increment}.
|
38 | 42 |
|
| 43 | +\pnum |
39 | 44 | When a constraint limits the form of an expression,
|
40 | 45 | parentheses are allowed around the expression
|
41 | 46 | or any required subexpression.
|
42 | 47 |
|
43 | 48 | \ssclause{Constraints on the form of the control clauses}
|
44 | 49 |
|
| 50 | +\pnum |
45 | 51 | \begin{cpp}
|
46 | 52 | The
|
47 | 53 | \nonterminal{condition}
|
|
55 | 61 | \end{note}
|
56 | 62 | \end{cpp}
|
57 | 63 |
|
| 64 | +\pnum |
58 | 65 | The controlling expression shall be a comparison expression
|
59 | 66 | with one of the following forms:%
|
60 | 67 | \footnote{DFEP:
|
|
75 | 82 | equality-expression \terminal{!=} relational-expression
|
76 | 83 | \end{bnf}
|
77 | 84 |
|
| 85 | +\pnum |
78 | 86 | Exactly one of the operands of the comparison operator
|
79 | 87 | shall be an identifier designating an induction variable,
|
80 | 88 | as described below.
|
|
87 | 95 | part of the limit expression.
|
88 | 96 | \end{cpp}
|
89 | 97 |
|
| 98 | +\pnum |
90 | 99 | The loop-increment shall be an expression with the following form:%
|
91 | 100 | \footnote{DFEP:
|
92 | 101 | OpenMP and ``classic'' Cilk allow only a single induction variable:
|
|
124 | 133 | identifier \terminal{=} additive-expression \terminal{+} identifier
|
125 | 134 | \end{bnf}
|
126 | 135 |
|
| 136 | +\pnum |
127 | 137 | \begin{cpp}
|
128 | 138 | Each comma in the grammar of loop-increment shall represent
|
129 | 139 | a use of the built-in comma operator.
|
|
144 | 154 | \defn{stride expression}
|
145 | 155 | for that induction variable.
|
146 | 156 |
|
| 157 | +\pnum |
147 | 158 | An induction variable shall not be designated by more than one
|
148 | 159 | \grammarterm{single-increment}.
|
149 | 160 |
|
|
169 | 180 |
|
170 | 181 | \ssclause{Other statically checkable constraints}
|
171 | 182 |
|
| 183 | +\pnum |
172 | 184 | Each induction variable shall have unqualified integral%
|
173 | 185 | \yescpp{,}
|
174 | 186 | \begin{cpp}
|
|
178 | 190 | or pointer type,
|
179 | 191 | and shall have automatic storage duration.
|
180 | 192 |
|
| 193 | +\pnum |
181 | 194 | Each stride expression shall have integral
|
182 | 195 | \begin{cpp}
|
183 | 196 | or enumeration
|
|
356 | 369 | \end{tabular}
|
357 | 370 | \end{table}
|
358 | 371 |
|
| 372 | +\pnum |
359 | 373 | The
|
360 | 374 | \defn{iteration count}
|
361 | 375 | is computed according to
|
|
369 | 383 | The iteration count expression shall be well-formed.
|
370 | 384 | \end{cpp}
|
371 | 385 |
|
| 386 | +\pnum |
372 | 387 | The type of the difference between the limit expression and the control variable
|
373 | 388 | is the
|
374 | 389 | \defn{subtraction type}\nocpp{.}%
|
|
406 | 421 | \end{tabular}
|
407 | 422 | \end{table}
|
408 | 423 |
|
| 424 | +\pnum |
409 | 425 | For each induction variable
|
410 | 426 | $V$,
|
411 | 427 | one of the expressions from
|
|
424 | 440 |
|
425 | 441 | \ssclause{Dynamic constraints}
|
426 | 442 |
|
| 443 | +\pnum |
427 | 444 | If an induction variable is modified within the loop
|
428 | 445 | other than as the side effect of its single-increment operation,
|
429 | 446 | the behavior of the program is undefined.%
|
|
439 | 456 | the behavior of the program is undefined.
|
440 | 457 | \end{cpp}
|
441 | 458 |
|
| 459 | +\pnum |
442 | 460 | If $X$ and $Y$ are values of the control variable
|
443 | 461 | that occur in consecutive evaluations of the loop condition
|
444 | 462 | in the serialization,%
|
|
456 | 474 | Unsigned wraparound is not allowed.
|
457 | 475 | \end{note}
|
458 | 476 |
|
| 477 | +\pnum |
459 | 478 | If the condition expression is true on entry to the loop,
|
460 | 479 | then the behavior is undefined
|
461 | 480 | if the computed iteration count is not greater than zero.
|
|
466 | 485 |
|
467 | 486 | \ssclause{Evaluation relaxations}
|
468 | 487 |
|
| 488 | +\pnum |
469 | 489 | The stride expressions shall not be evaluated if the iteration count is zero;
|
470 | 490 | otherwise,
|
471 | 491 | the stride and limit expressions are evaluated exactly once.%
|
|
477 | 497 | %of the increment or limit expression,
|
478 | 498 | %the behavior is undefined.
|
479 | 499 |
|
| 500 | +\pnum |
480 | 501 | Within each iteration of the loop body,
|
481 | 502 | the name of each induction variable refers to a local object,
|
482 | 503 | as if the name were declared as an object within the body of the loop,
|
|
489 | 510 |
|
490 | 511 | \begin{cpp}
|
491 | 512 | \sclause{Constraints on a counted range-based \tcode{for} statement}
|
| 513 | +\pnum |
492 | 514 | In a counted range-based
|
493 | 515 | \tcode{for}
|
494 | 516 | statement ([stmt.ranged] 6.5.4),
|
|
504 | 526 | \tcode{for}
|
505 | 527 | statement.
|
506 | 528 | \end{note}
|
507 |
| -\end{cpp} |
| 529 | +\end{cpp} |
0 commit comments