如何在 GCC 中摆脱“已弃用的从字符串常量到‘char*’的转换"警告?

2023-04-11C/C++开发问题
100

本文介绍了如何在 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*’的转换"警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6