小编km3*_*m3h的帖子

C中的双指针常量正确性警告

指向非const数据的指针可以隐式转换为指向相同类型的const数据的指针:

int       *x = NULL;
int const *y = x;
Run Code Online (Sandbox Code Playgroud)

添加额外的const限定符以匹配额外的间接寻址应该在逻辑上以相同的方式工作:

int       *      *x = NULL;
int       *const *y = x; /* okay */
int const *const *z = y; /* warning */
Run Code Online (Sandbox Code Playgroud)

-Wall但是,使用标志对GCC或Clang进行编译会产生以下警告:

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 */
                      ^   ~
Run Code Online (Sandbox Code Playgroud)

为什么添加额外的const限定符"在嵌套指针类型中丢弃限定符"?

c const qualifiers multiple-indirection implicit-conversion

53
推荐指数
2
解决办法
1万
查看次数