qualifiers

Double pointer const-correctness warnings in C

隐身守侯 提交于 2019-11-26 01:45:40
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; /*

Double pointer const-correctness warnings in C

安稳与你 提交于 2019-11-26 00:48:25
问题 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