在gcc 3.4中抑制特定警告

3

我想摆脱以下警告信息:

warning: initialization discards `const' from pointer target type

代码需要保持原样,因此在VS中使用了Suppress Specific Warning,但我想知道是否有办法在gcc中实现相同的功能。

使用相当旧的GCC编译器3.4,我遇到的所有其他帖子都谈论更高版本。 一些有用的帖子-

如何在g ++中抑制特定警告

http://www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html

https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Warning-Options.html

尝试使用-

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
//< code that generates warning >
#pragma GCC diagnostic pop

但是警告增加了-
: warning: ignoring pragma: push
: warning: ignoring pragma: "-Wignored-qualifiers
: warning: initialization discards `const' from pointer target type
: warning: initialization discards `const' from pointer target type
: warning: ignoring pragma: pop

5
“daignostic”是拼写错误吗? - ouah
2
gcc 3.4: 听起来很有趣 - m.s.
1
如果gcc 3.4不支持这些#pragma指令,您也可以使用“-Wignored-qualifiers”编译存在问题的源文件。 - ouah
2
你通常可以通过显式转换来避免警告,例如 char * s = (char *)“不要修改我”。尽管警告是有原因的。 - rici
2
@Maverick,如果你开始使用同一个程序但在新平台上或者只是在另一个编译器上如gcc,这里给出的参数就不适用了。gcc可能会对你所掩盖的同一未定义行为做出不同的处理。根据上下文,这可能是不负责任的。 - Jens Gustedt
显示剩余8条评论
1个回答

2

请注意:

<gcc.gnu.org/onlinedocs/gcc/Option-Summary.html>; 

请查看GCC选项列表:

<gcc.gnu.org/onlinedocs/gcc/…; 

有关更详细的描述,请参见此链接。

此链接:

<gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>

他说:
"Each of these specific warning options also has a negative form beginning ' -Wno- ' to turn off warnings; 

for example, -Wno-implicit ."

它报错了 **cc1plus: error: Invalid option `-Wno-ignored-qualifiers'**。看起来旧版本不支持它。尝试使用 -Wno-discarded-qualifiers。链接 - Maverick
我们如何知道哪个标志实际上会触发“warning: initialization discards `const' from pointer target type”这个警告? - Maverick
使用以下编译器标志:`COMP_FLAGS +=
-Wall \ -Wno-cast-qual \ -Wno-comment
-D_VMOS
-DLYNXOS
-fno-rtti
-fno-exceptions
-mminimal-toc
-fno-builtin
-D__STDC_LIMIT_MACROS`顺序会影响吗?
- Maverick
COMP_FLAGS列表中的所有\\是什么意思?它们在编译器标志列表中无效。 - user3629249
关于错误信息中的 cc1plus:通常是由于尝试使用 gcc 编译 c++ 文件所致。或者源文件使用的是 utf-16 格式而不是 utf-8 格式。 - user3629249
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接