A pointer to non-const data can be implicitly converted to a pointer to const data of the same type:
int *x = NULL;
int const *y = x;
Adding additional const qualifiers to match the additional indirection should logically work the same way:
int * *x = NULL;
int *const *y = x; /* okay */
int const *const *z = y; /* warning */
Compiling this with GCC or Clang with the -Wall
flag, however, results in the following warning:
test.c:4:23: warning: initializing 'int const *const *' with an expression of type
'int *const *' discards qualifiers in nested pointer types
int const *const *z = y; /* warning */
^ ~
Why does adding an additional const
qualifier "discard qualifiers in nested pointer types"?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…