ISO/ IEC JTC1/SC22/WG14 N721

ISO/IEC JTC1/SC22/WG14 N721

                      Unary * operator - a fix
                          Clive D.W. Feather


Abstract
========

DR076 and N697 address the issue of code like:

    int a[10], *p;
    for (p = &a[0]; p < &a[10]; p++)
        /* ... */

Without rehashing the issues, this proposal fixes the problems by
avoiding them. The approach is that of N720 item DR076, but has some
wording improvements.


Proposal
========

In 6.3.3.2, change the first constraint (paragraph 1) from:

    The operand of the unary & operator shall be a function designator
    or an lvalue that designates an object that is not a bit-field and
    is not declared with the /register/ storage-class specifier.

to:

    The operand of the unary & operator shall be a function designator,
 |  the result of a [] or unary * operator,
    or an lvalue that designates an object that is not a bit-field and
    is not declared with the /register/ storage-class specifier.

Add to the end of paragraph 3:

    If the operand is the result of a unary * operator, neither that
    operator nor the & operator are evaluated, and the result shall
    be as if both were omitted, even if the intermediate object does not
    exist. Similarly, if the operand is the result of a [] operator, 
    neither the & operator nor the unary * that is implied by the []
    are evaluated, and the result shall be as if the & operator was
    removed and the [] operator was changed to a + operator.

Change the first sentence of footnote 54 to:

    Thus &*E is equivalent to E (even if E is a null pointer), and
    &(E1[E2]) to (E1+E2).

In 6.3.6 paragraph 8, change the last sentence from:

    ... the behaviour is undefined if the result is used as an operand
    of the unary * operator.

to:

    ... the behaviour is undefined if the result is used as an operand
    of a unary * operator that is actually evaluated.