3
这里是我的测试程序:为什么GCC 4.2.1在某些情况下忽略#pragma GCC诊断忽略“-Wcast-qual”?
#include <stdio.h>
#pragma GCC diagnostic ignored "-Wcast-qual"
static void proc(char *buf)
{
printf("buf=%p\n",buf);
}
int main(int argc,char **argv)
{
const char *cbuf;
char *buf = (char *)cbuf;
proc(buf);
return(0);
}
这里是我的编译:
$ g++ -Wcast-qual x.cpp
x.cpp: In function ‘int main(int, char**)’:
x.cpp:13: warning: cast from type ‘const char*’ to type ‘char*’ casts away constness
$
这里是没有-Wcast-QUAL编译:
$ g++ x.cpp
$
我用#pragma GCC diagnostic ignored
在我的代码的其他地方没有问题。这里不起作用。有人可以告诉我为什么吗?