【问题标题】:warning: type qualifiers ignored on function return type in gcc 4.1.2警告:在 gcc 4.1.2 中函数返回类型上忽略类型限定符
【发布时间】:2013-03-13 20:44:19
【问题描述】:

我在 Linux 上使用 gcc 4.1.2,遇到以下警告:

warning: type qualifiers ignored on function return type

我尝试使用“-Wno-ignored-qualifiers”来消除此警告,但似乎不支持:

cc1: error: unrecognized command line option "-Wno-ignored-qualifiers"

有没有办法在 gcc 4.1.2 中禁用此类警告?

非常感谢。

【问题讨论】:

  • 什么代码/行导致了这个警告?
  • 函数返回“const char *”
  • first google search result for the warning(不要离开这里...)
  • @user1783732:如果它返回一个const char *,那么它不应该引起这个警告,因为该限定符是有意义的并且不会被忽略。你一定有别的东西。为什么不显示导致警告的实际代码?可能是您实际上有一个 char * const,而您的真正意思是 const char *,但您对宏或 typedef 感到困惑,这就是警告警告您的原因

标签: c linux gcc


【解决方案1】:

找到了解决方案。使用:

-Wno-return-type

【讨论】:

  • 我认为禁用警告不是一个好主意,应该编译具有高警告级别-Wall 的代码。顺便说一句,您可以接受自己的答案,以便将问题标记为已解决。
  • 禁用警告并认为问题“已修复”确实是一个可怕的想法,除非您对关闭它的原因有非常非常的了解,这是一个在你的代码中做合法的事情。这在实践中非常罕见。
  • 问题是我无法修改源代码。我要在不修改源代码的情况下找到解决方案。
【解决方案2】:

作为seen hereconst char *不会触发该警告。

const char 会,避免该警告的正确方法是,如果可能,将返回类型从 const char 更改为 char

参见 Junio C Hamano (gitster)commit ee5462d(2017 年 12 月 27 日)示例,用于 Git 2.16(2018 年第一季度)。

sequencer.c:从函数返回类型中删除“const

-Werror=ignored-qualifiers,一个声称返回的函数 “const char”得到这个错误:

   CC sequencer.o
sequencer.c:798:19: error: type qualifiers ignored on function return
type [-Werror=ignored-qualifiers]
 static const char command_to_char(const enum todo_command command)
                   ^

【讨论】:

    猜你喜欢
    • 2010-11-11
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    相关资源
    最近更新 更多