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

How to get rid of `deprecated conversion from string constant to ‘char*’` warnings in GCC?(如何在 GCC 中摆脱“已弃用的从字符串常量到‘char*’的转换警告?)
本文介绍了如何在 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*’的转换"警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Prevent class inheritance in C++(防止 C++ 中的类继承)
Why should I declare a virtual destructor for an abstract class in C++?(为什么要在 C++ 中为抽象类声明虚拟析构函数?)
Why is Default constructor called in virtual inheritance?(为什么在虚拟继承中调用默认构造函数?)
C++ cast to derived class(C++ 转换为派生类)
C++ virtual function return type(C++虚函数返回类型)
Is there any real risk to deriving from the C++ STL containers?(从 C++ STL 容器派生是否有任何真正的风险?)