Files
cppdraft_translate/cppdraft/dcl/ptr.md
2025-10-25 03:02:53 +03:00

3.7 KiB
Raw Blame History

[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]

1

#

In a declarationTD whereD has the form

and the type of the contained declarator-id in the declarationTD1 is “derived-declarator-type-list€, 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.

2

#

[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]

3

#

See also [expr.assign] and [dcl.init].

4

#

[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]