3.7 KiB
[dcl.ptr]
9 Declarations [dcl]
9.3 Declarators [dcl.decl]
9.3.4 Meaning of declarators [dcl.meaning]
9.3.4.2 Pointers [dcl.ptr]
In a declarationTD whereD has the form
- attribute-specifier-seqopt cv-qualifier-seqopt D1
and the type of the contained declarator-id in the declarationTD1 is âderived-declarator-type-listTâ, the type of the declarator-id inD is âderived-declarator-type-list cv-qualifier-seq pointer toTâ.
Thecv-qualifiers apply to the pointer and not to the object pointed to.
Similarly, the optional attribute-specifier-seq ([dcl.attr.grammar]) appertains to the pointer and not to the object pointed to.
[Example 1:
The declarationsconst int ci = 10, *pc = &ci, *const cpc = pc, **ppc;int i, *p, *const cp = &i; declareci, a constant integer;pc, a pointer to a constant integer;cpc, a constant pointer to a constant integer;ppc, a pointer to a pointer to a constant integer;i, an integer;p, a pointer to integer; andcp, a constant pointer to integer.
The value ofci,cpc, andcp cannot be changed after initialization.
The value ofpc can be changed, and so can the object pointed to bycp.
Examples of some correct operations arei = ci;*cp = ci; pc++; pc = cpc; pc = p; ppc = &pc;
Examples of ill-formed operations areci = 1; // error ci++; // error*pc = 2; // error cp = &ci; // error cpc++; // error p = pc; // error ppc = &p; // error
Each is unacceptable because it would either change the value of an object declaredconst or allow it to be changed through a cv-unqualified pointer later, for example:ppc = &ci; // OK, but would make p point to ci because of previous errorp = 5; // clobber ci
â end example]
See also [expr.assign] and [dcl.init].
[Note 1:
Forming a pointer to reference type is ill-formed; see [dcl.ref].
Forming a function pointer type is ill-formed if the function type hascv-qualifiers or a ref-qualifier; see [dcl.fct].
Since the address of a bit-field ([class.bit]) cannot be taken, a pointer can never point to a bit-field.
â end note]