简体   繁体   English

如何摆脱这些警告?

[英]How do I get rid of these warnings?

This is really several questions, but anyway... 这确实是几个问题,但无论如何...

I'm working with a big project in XCode, relatively recently ported from MetroWorks (Yes, really) and there's a bunch of warnings that I want to get rid of. 我正在处理XCode中的一个大项目,相对较新的是最近从MetroWorks移植的(是的,是的),并且有很多我想摆脱的警告。 Every so often an IMPORTANT warning comes up, but I never look at them because there's too many garbage ones. 每隔一段时间就会出现一个重要警告,但我从未看过它们,因为有太多的垃圾警告了。 So, if I can either figure out how to get XCode to stop giving the warning, or actually fix the problem, that would be great. 因此,如果我可以弄清楚如何使XCode停止发出警告,或者实际上解决问题,那将是很好的。 Here are the warnings: 以下是警告:

  • It claims that <map.h> is antiquated. 它声称<map.h>是过时的。 However, when I replace it with <map> my files don't compile. 但是,当我用<map>替换它时,我的文件无法编译。 Evidently, there's something in map.h that isn't in map... 显然,map.h中有一些不在地图中...
  • this decimal constant is unsigned only in ISO C90 此十进制常量仅在ISO C90中是无符号的
    This is a large number being compared to an unsigned long. 与无符号长整数相比,这是一个很大的数字。 I have even cast it, with no effect. 我什至都没有效果。
  • enumeral mismatch in conditional expression: <anonymous enum> vs <anonymous enum> 条件表达式中的枚举不匹配: <anonymous enum><anonymous enum>
    This appears to be from a ?: operator. 这似乎来自?:运算符。 Possibly that the then and else branches don't evaluate to the same type? 可能then和else分支的计算结果不相同吗? Except that in at least one case, it's (matchVp == NULL ? noErr : dupFNErr) 至少在一种情况下是(matchVp == NULL ? noErr : dupFNErr)

    And since those are both of type OSErr, which is mac defined... I'm not sure what's up. 而且由于它们都是OSErr类型,这是mac定义的...我不确定是怎么回事。 It also seems to come up when I have other pairs of mac constants... 当我有其他成对的Mac常数时,它似乎也会出现...

  • multi-character character constant 多字符常量

    This one is obvious. 这是显而易见的。 The problem is that I actually NEED multi-character constants... 问题是我实际上需要多字符常量。

  • -fwritable-strings not compatible with literal CF/NSString -fwritable-strings与文字CF / NSString不兼容

    I unchecked the "Strings are Read-Only" box in both the project and target settings... and it seems to have had no effect... 我在项目和目标设置中都未选中“字符串是只读的”框...似乎没有任何作用...

Items in <map.h> are in the global namespace while items in <map> are in the std namespace. <map.h>中的项目位于全局名称空间中,而<map>中的项目位于std名称空间中。 Most likely you were just referring directly to the global versions and when you switched to <map> you were no longer seeing them because they moved to std:: . 您很可能只是直接引用全局版本,而当您切换到<map>您不再看到它们,因为它们已移至std:: In source files add a using namespace std to move on quickly. 在源文件中添加一个using namespace std以快速进行操作。 In headers you'll need to qualify uses of map-related items with std:: . 在标题中,您需要使用std::限定地图相关项的使用。

I think you'll need to qualify the literal constant value with a trailing UL so it knows the correct type of the literal. 我认为您需要使用尾随的UL限定文字常量值,以便它知道文字的正确类型。

Most likely the enums are in two separate OS defined anonymous enums. 枚举很可能位于两个单独的OS定义的匿名枚举中。 You can static_cast them to quiet the warning. 您可以static_cast他们以静默警告。

No idea on the multi-byte chars. 不知道多字节字符。

Can you disable -fwritable-strings? 您可以禁用-fwritable-strings吗? Can you refactor the code that needs to modify constant strings? 您可以重构需要修改常量字符串的代码吗?

"multi-character character constant" “多字符常量”
This one is obvious. 这是显而易见的。 The problem is that I actually NEED multi-character constants... 问题是我实际上需要多字符常量。

Compile with -Wno-multichar -- add it to Other Warning Flags, and leave the Four Character Literals warning switched off. 使用-Wno-multichar编译-将其添加到“其他警告标志”,并关闭“四字符文字”警告。

Of course, whether this legacy code's multi-character character constants actually mean the same thing as they did under Metrowerks probably on a different architecture... is an open question. 当然,这个遗留代码的多字符字符常量是否实际上与在Metrowerks下对同一体系结构的含义相同……这是一个悬而未决的问题。

该十进制常数写为3111222333UL吗?

I discovered that at least as of Xcode 3.2.4 you can make the warning go away by using a number of characters in the constant that is the correct length for the type. 我发现至少从Xcode 3.2.4开始,您可以通过在常量中使用多个字符来消除该警告,该常量是该类型的正确长度。

For example I had a constant that was only 3 chars long 'TT2' and it was giving me the multi-character character constant error. 例如,我有一个仅3个字符长的常量“ TT2”,这给了我多字符字符常量错误。 Adding 0's to the constant made the errors go away, like so: '\\0TT2'. 在常量上加0将使错误消失,例如:'\\ 0TT2'。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM