Can someone explain to me the following quote from C Standard? No matter how much I try to make sense of this I can't and how is someone, even if they are experienced in C, supposed to understand this?
C 2018 6.7.6.1 1 says:
If, in the declaration “T D1”, D1 has the form
* type-qualifier-listopt D
and the type specified for ident in the declaration “T D” is “derived-declarator-type-list T”, then the type specified for ident is “derived-declarator-type-list type-qualifier-list pointer to T”. For each type qualifier in the list, ident is a so-qualified pointer.
First consider that T D
declares the identifier inside D
to be of some type derived from T
. There might be nothing added; int foo
declares foo
to be int
. Or the declarator D
might include brackets […]
so that it adds “array of”, or it might include parentheses so it adds “function returning”, or it might include an asterisk so it adds “pointer to”, or it may have combinations of these (including possible repetitions). The text asked about says that inserting *
to make T D
into T *D
changes the declaration by inserting “pointer of” after the other derived parts and before the T
. For example, changing int foo(void)
to int *foo(void)
changes the type from “function returning int
” to “function returning pointer to int
”.
Here is a more detailed analysis.
Ignoring the qualifiers for the moment, the clause “If, in the declaration ‘T D1’, D1 has the form * type-qualifier-listopt D” tells us to consider a declaration with the form T *D
.
The next clause, “and the type specified for ident in the declaration ‘T D’ is ‘derived-declarator-type-list T’,” tells us to consider what T *D
would be without the *
, as if it were just T D
. Now, inside D
, there is some identifier, called ident. D
could be just ident
, or it could an array declarator, like ident[3]
, or a function declarator, ident(void)
, or another pointer declarator, *ident
, or a combination of those, including repetitions. Whatever it is, T D
declares ident to be something. Let’s say it declares the type of ident to be “derived-stuff T
”.
The final clause of that sentence, “then the type specified for ident is ‘derived-declarator-type-list type-qualifier-list pointer to T’”, tells us that if T D
declares ident to be of type “derived-stuff T
”, then T *D
declares ident to be of type “derived-stuff pointer to T
”.
Bringing back the qualifiers, the final sentence tells us any qualifiers in the indicated position (const
, restrict
, volatile
, and/or _Atomic
between the *
and the D
), apply to ident.