简体   繁体   English

使用typedef摆脱GCC中从字符串常量到'char *'的过时转换警告?

[英]get rid of `deprecated conversion from string constant to ‘char*’` warnings in GCC using typedefs?

I'm working on updating a very large codebase to be able to use gcc4.3 and ran into this issue. 我正在更新一个非常大的代码库,以便能够使用gcc4.3并遇到此问题。 The question has been asked several times, however I think my situation is a little unique and Haven't been able to get a good explanation out of it. 这个问题已经问了好几次了,但是我认为我的情况有点特殊,还没有得到很好的解释。

The error I get is 我得到的错误是

error: deprecated conversion from string constant to 'realchar {aka char*}' 错误:不建议从字符串常量转换为'realchar {aka char *}'

realchar refers to a typedef I have: realchar指的是我拥有的typedef:

typedef char*   realchar;

public:
ClassNameIsMe(const realchar name="UsyncBndLNQueue");

changing realChar to be simply char* removes the warning. 将realChar更改为char *可以删除警告。 however shouldn't that be equivalent since it is a typedef pointing to char*? 但是那不是等效的,因为它是指向char *的typedef吗?

The problem is that const realchar name is const pointer to char, ie it is equivalent to: 问题在于const realchar name是指向char的const指针,即,它等效于:

char * name const

instead of pointer to const char, which would be equivalent to: 而不是指向const char的指针,它等效于:

const char * name

So the warning is valid. 因此,警告有效。


See details here: 在这里查看详细信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何摆脱 GCC 中从字符串常量到“char*”的“已弃用转换”警告? - How to get rid of `deprecated conversion from string constant to ‘char*’` warnings in GCC? 从字符串常量到'char *'的错误不建议使用的转换 - ERROR deprecated conversion from string constant to 'char*' 从字符串常量到'char *'的不推荐使用转换:不能使用常量 - Deprecated conversion from string constant to 'char*': Can't use the constant 如何在GCC中弃用已弃用的函数中删除已弃用的警告? - How can I get rid of deprecated warnings in deprecated functions in GCC? 消除从字符串常量到'char *'的弃用转换的最佳方法” - Best way to eliminate deprecated conversion from string constant to ‘char*’" 在CUDA分配模板函数中不建议将字符串常量转换为'char *' - Deprecated conversion from string constant to 'char *' in CUDA allocation template function C ++不推荐将字符串常量转换为'char *' - C++ deprecated conversion from string constant to 'char*' 从字符串常量到'char *'[-Wwrite-strings]的弃用转换 - deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] 如何避免在C ++中不推荐将字符串常量转换为'char *' - How to avoid deprecated conversion from string constant to 'char*' in C++ C ++ - 从字符串常量到char的不推荐的转换 - C++ - Deprecated conversion from string constant to char
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM