为什么GCC 4.2.1忽略“pragma GCC诊断忽略”-Wcast qual“;在某些条件下?
这是我的测试程序:为什么GCC 4.2.1忽略“pragma GCC诊断忽略”-Wcast qual“;在某些条件下?,gcc,pragma,Gcc,Pragma,这是我的测试程序: #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); retu
#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);
}
下面是不带-Wcast-qual的编译:
$ g++ x.cpp
$
我在代码的其他地方使用了
#pragma GCC diagnostic ignored
,没有任何问题。在这里,它不起作用。有人能告诉我为什么吗?这是Mac上的一个编译器错误。Linux上的GCC4.7.2没有这个问题。clang++也没有。在Mac上,您应该尝试使用clang++,而不是g++
苹果应该更新它的编译器
$ g++ x.cpp
$