How to get rid of `deprecated conversion from string constant to ‘char*’` warnings in GCC?(如何在 GCC 中摆脱“已弃用的从字符串常量到‘char*’的转换警告?)
问题描述
所以我正在处理一个非常大的代码库,最近升级到 gcc 4.3,现在触发了这个警告:
So I'm working on an exceedingly large codebase, and recently upgraded to gcc 4.3, which now triggers this warning:
警告:不推荐将字符串常量转换为‘char*’
warning: deprecated conversion from string constant to ‘char*’
显然,解决这个问题的正确方法是找到每个声明,如
Obviously, the correct way to fix this is to find every declaration like
char *s = "constant string";
或函数调用,如:
void foo(char *s);
foo("constant string");
并使它们成为 const char
指针.但是,这意味着最少要接触 564 个文件,这不是我目前希望执行的任务.现在的问题是我使用 -werror
运行,所以我需要一些方法来抑制这些警告.我该怎么做?
and make them const char
pointers. However, that would mean touching 564 files, minimum, which is not a task I wish to perform at this point in time. The problem right now is that I'm running with -werror
, so I need some way to stifle these warnings. How can I do that?
推荐答案
我相信将 -Wno-write-strings
传递给 gcc 会抑制这个警告.
I believe passing -Wno-write-strings
to gcc will suppress this warning.
这篇关于如何在 GCC 中摆脱“已弃用的从字符串常量到‘char*’的转换"警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 GCC 中摆脱“已弃用的从字符串常量到‘char*’的转换"警告?
- 近似搜索的工作原理 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- C++ 协变模板 2021-01-01