标签:错误 top UNC com ubuntu sign warning type har
1、告警test_cpp.c
#include <stdlib.h>
#include <stdio.h>
int main()
{
char c = ‘c‘;
char c_q = ‘c‘;
char *p = &c;
char *q = &c_q;
char **pp = &p;
const char **cpp = &p;
char const **c_pp = &p;
char * const *pcp = &p;
char ** const ppc = &p;
return 0;
}
编译的时候有如下警告:
x@ubuntu:~/Desktop/const$ gcc text_cpp.c
text_cpp.c: In function ‘main’:
text_cpp.c:13:21: warning: initialization of ‘const char **’ from incompatible pointer type ‘char **’ [-Wincompatible-pointer-types]
const char **cpp = &p;
^
text_cpp.c:14:22: warning: initialization of ‘const char **’ from incompatible pointer type ‘char **’ [-Wincompatible-pointer-types]
char const **c_pp = &p;
^
#include <stdlib.h>
#include <stdio.h>
int main()
{
char *p_str[] = {"char **",
"const char ** ",
"char * const * ",
"char ** const ",};
char **pp = p_str;
const char **cpp = p_str;
char * const *pcp = p_str;
char ** const ppc = p_str;
*pp = "assign char **";
*cpp = "assign const char **";
*pcp = "assign char * const *";
*ppc = "assign char ** const";
return 0;
}
出现如下编译错误:
x@ubuntu:~/Desktop/const$ gcc text_cpp.c
text_cpp.c: In function ‘main’:
text_cpp.c:12:21: warning: initialization of ‘const char **’ from incompatible pointer type ‘char **’ [-Wincompatible-pointer-types]
const char **cpp = p_str;
^~~~~
text_cpp.c:18:7: error: assignment of read-only location ‘*pcp’
*pcp = "assign char * const *";
^
const char **,char *const *,char ** const
标签:错误 top UNC com ubuntu sign warning type har
原文地址:https://blog.51cto.com/iamokay/2426525