【问题标题】:Removing NSInteger warning using __LINE__使用 __LINE__ 删除 NSInteger 警告
【发布时间】:2014-11-04 19:14:27
【问题描述】:

我有一个日志功能:

#define LOGERROR(err) if(err) {                     \
    LOGTRACE(@"[NSError] %s (%d): (%d:%@) Reason: %@",  \
        __PRETTY_FUNCTION__,                            \
        __LINE__,                                       \
        err.code,                                       \
        err.domain,                                     \
        err.localizedDescription)                       \
}

当我用

调用它时
LOGERROR(playerItem.error);

我收到警告:“NSInteger 不应用作格式参数,应将显式强制转换添加到 long”。

Xcode 的 autofix 在 LOGERROR 之前插入 %ld,这是错误的。

我认为这个警告来自__LINE__ 的使用,根据https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html 返回一个int。

如何从这个调用中删除警告?

【问题讨论】:

  • 我认为它实际上对err.code 感到恼火,它返回一个NSInteger。投射它:(long)(err.code),然后在格式字符串中使用%ld
  • 啊,谢谢。只是误读了。

标签: objective-c c-preprocessor iphone-64bit


【解决方案1】:

只是为了正式确定我在评论中给出的答案:

编译器抱怨err.code 的使用,它返回一个NSInteger。将其转换为long:(long)(err.code),然后在格式字符串中使用%ld

【讨论】:

    猜你喜欢
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 2019-01-15
    • 2016-01-29
    • 1970-01-01
    相关资源
    最近更新 更多