【问题标题】:Compile error related to "index"- is it actually a function?与“索引”相关的编译错误 - 它实际上是一个函数吗?
【发布时间】:2009-06-03 19:23:30
【问题描述】:

我正在从我们的编译中删除所有警告,并遇到以下问题:

警告:` 的地址 char* index(const char*, int)', 永远是'true'

对于以下代码行:

DEBUG_MSG("Data received from Device "<<(int)_nodeId << "for" << index  <<(int)msgIn.index<<".");

DEBUG_MSG 是我们的日志记录宏之一,预处理器将其替换为采用 C++ 样式流操作的语句。

index 似乎没有被声明,所以我假设它应该是这样的:

DEBUG_MSG("Data received from Device "<<(int)_nodeId << "for index "  <<(int)msgIn.index<<".");

并且 index 将是标准库中“char* index(const char*, int)”函数的函数*,但 index 函数有什么作用?谷歌似乎没用,因为它会提取与 C++ 相关的书籍索引。

在我对此警告的解释中是否遗漏了什么?

【问题讨论】:

    标签: c++ gcc-warning


    【解决方案1】:

    【讨论】:

    • 谢谢,这巩固了正在发生的事情,并且这不是原始用户想要的。
    【解决方案2】:

    据推测,流运营商正在看到

    << index
    

    并尝试自动将其转换为可以打印的内容:

    << (bool)index
    

    但是 index 是一个函数,并且有一个永远不会为 NULL 的地址。所以这相当于:

    << true
    

    G++ 看到这将永远是正确的,并发出警告。

    至于索引的作用,见http://www.linuxmanpages.com/man3/index.3.php

    【讨论】:

      【解决方案3】:

      index&lt;strings.h&gt; 中定义的函数,已弃用,应替换为strchr

      【讨论】:

        猜你喜欢
        • 2020-12-21
        • 2021-01-11
        • 2021-12-03
        • 2015-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-15
        • 2010-10-17
        相关资源
        最近更新 更多