Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么GCC 4.2.1忽略“pragma GCC诊断忽略”-Wcast qual“;在某些条件下?_Gcc_Pragma - Fatal编程技术网

为什么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
$