ISO/ IEC JTC1/SC22/WG14 N740

ISO/IEC JTC1/SC22/WG14 N740

                   Mixing declarations and code
                     Final wording changes
                       Clive D.W. Feather


Related Documents: N503, N712


In 6.1.2.4, third paragraph, replace:

    If an initialization is specified for the value stored in the
    object, it is performed on each normal entry, but not if the block
    is entered by a jump to a labelled statement.

with:

    If an initialization is specified for the value stored in the
    object, it is performed on each normal entry, but not if the block
 |  is entered by a jump to a labelled statement beyond the declaration.
 |  A backwards jump might cause the initializer to be evaluated more
 |  than once; if so, a new value will be stored each time.


Replace subclause 6.6.2 syntax by:

    compound-statement:
 |      { block-item-list-opt }
 |
 |  block-item-list:
 |      block-item
 |      block-item-list block-item
 |
 |  block-item:
 |      declaration
 |      statement

Change 6.6.2 paragraph to from:

    A compound statement (also called a block) allows a set
    of statements to be grouped into one syntactic unit, which
    may have its own set of declarations and initializations (as
    discussed in 6.1.2.4). The initializers of objects that
    have automatic storage duration are evaluated and the values
    are stored in the objects in the order their declarators
    appear in the translation unit.

to:

    A compound statement (also called a block) allows a set
    of statements to be grouped into one syntactic unit, which
    may have its own set of declarations and initializations (as
    discussed in 6.1.2.4). The initializers of objects that
    have automatic storage duration are evaluated and the values
 |  are stored in the objects (including storing an indeterminate
 |  value in objects without an initializer) each time that the
 |  declaration is reached in the order of execution, as if it
 |  were a statement, and within each declaration in the order
 |  that the declarators appear.

Change the 6.6.5 syntax from:

    iteration-statement:
        while ( expression ) statement
        do statement while ( expression ) ;
        for ( expression-opt ; expression-opt ; expression-opt } statement

to:

    iteration-statement:
        while ( expression ) statement
        do statement while ( expression ) ;
        for ( expression-opt ; expression-opt ; expression-opt } statement
 |      for ( declaration    ; expression-opt ; expression-opt } statement

Replace 6.6.5.3 by:

    Except for the behaviour of a continue statement in the loop body,
    the statement

 |      for ( clause-1 ; expression-2 ; expression-3 ) statement
 |
 |  and the block
 |
 |      {
 |          clause-1 ;
 |          while ( expression-2 ) {
 |              statement
 |              expression-3 ;
 |          }
 |      }
 |
 |  are equivalent (where clause-1 can be an expression or a
 |  declaration). [93]

 |  Both clause-1 and expression-3 can be omitted. If either or both
 |  are an expression, they are evaluated as as a void expression.
    An omitted expression-2 is replaced by a nonzero constant.

Change footnote 93 from:

    [93] Thus, expr-1 specifies initialization for the loop;
    expr-2, the controlling expression, specifies an
    evaluation made before each iteration, such that
    execution of the loop continues until the expression
    compares equal to 0; expr-3 specifies an operation (such
    as incrementing) that is performed after each iteration.

to:

 |  [93] Thus, clause-1 specifies initialization for the loop,
 |  possibly declaring one or more variables for use in the loop;
    expr-2, the controlling expression, specifies an
    evaluation made before each iteration, such that
    execution of the loop continues until the expression
    compares equal to 0; expr-3 specifies an operation (such
    as incrementing) that is performed after each iteration.
 |  If clause-1 is a declaration, then the scope of any variable it
 |  declares is the remainder of the declaration and the entire loop,
 |  including the other two expressions.

========

At the WG14 London meeting, the document was amended prior to approval
by adding a further editing instruction:

Add a Constraint to subclause 6.6.5:

    The declaration in a for loop shall only have a storage class of
    auto or register.