6.7.3 Type qualifiers

Previous Table of Contents "New C Standard" commentary

1476

type-qualifier:
                const
                restrict
                volatile

1477 Types other than pointer types derived from object or incomplete types shall not be restrict-qualified.

1478 The properties associated with qualified types are meaningful only for expressions that are lvalues.112)

1479 If the same qualifier appears more than once in the same specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it appeared only once.

1480 If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified type, the behavior is undefined.

1481 If an attempt is made to refer to an object defined with a volatile-qualified type through use of an lvalue with non-volatile-qualified type, the behavior is undefined.113)

1482 An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects.

1483 Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine, as described in 5.1.2.3.

1484 Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously.114)

1485 112) The implementation may place a const object that is not volatile in a read-only region of storage.

1486 Moreover, the implementation need not allocate storage for such an object if its address is never used.

1487 113) This applies to those objects that behave as if they were defined with qualified types, even if they are never actually defined as objects in the program (such as an object at a memory-mapped input/output address).

1488 What constitutes an access to an object that has volatile-qualified type is implementation-defined.

1489 An object that is accessed through a restrict-qualified pointer has a special association with that pointer.

1490 This association, defined in 6.7.3.1 below, requires that all accesses to that object use, directly or indirectly, the value of that particular pointer.115)

1491 The intended use of the restrict qualifier (like the register storage class) is to promote optimization, and deleting all instances of the qualifier from all preprocessing translation units composing a conforming program does not change its meaning (i.e., observable behavior).

1492 If the specification of an array type includes any type qualifiers, the element type is so-qualified, not the array type.

1493 If the specification of a function type includes any type qualifiers, the behavior is undefined.116)

1494 For two qualified types to be compatible, both shall have the identically qualified version of a compatible type;

1495 the order of type qualifiers within a list of specifiers or qualifiers does not affect the specified type.

1496 EXAMPLE 1 An object declared


        extern const volatile int real_time_clock;

may be modifiable by hardware, but cannot be assigned to, incremented, or decremented.

1497 EXAMPLE 2 The following declarations and expressions illustrate the behavior when type qualifiers modify an aggregate type:


        const struct s { int mem; } cs = { 1 };
        struct s ncs;  // the object ncs is modifiable
        typedef int A[2][3];
        const A a = {{4, 5, 6}, {7, 8, 9}}; // array of array of const int
        int *pi;
        const int *pci;
        
        ncs = cs;      // valid
        cs = ncs;      // violates modifiable lvalue constraint for =
        pi = &ncs.mem; // valid
        pi = &cs.mem;  // violates type constraints for =
        pci = &cs.mem; // valid
        pi = a[0];     // invalid: a[0] has type "const int *"

1498 114) A volatile declaration may be used to describe an object corresponding to a memory-mapped input/output port or an object accessed by an asynchronously interrupting function.

1499 Actions on objects so declared shall not be “optimized out” by an implementation or reordered except as permitted by the rules for evaluating expressions.

1500 115) For example, a statement that assigns a value returned by malloc to a single pointer establishes this association between the allocated object and the pointer.

1501 116) Both of these can occur through the use of typedefs.

Next

Created at: 2008-01-30 02:39:43 The text from WG14/N1256 is copyright © ISO