与“index”相关的编译错误 - 它实际上是一个函数吗?

发布于 2024-07-22 05:30:39 字数 647 浏览 7 评论 0原文

我正在从编译中删除所有警告,并遇到以下内容:

警告:`的地址 行将始终为“true”

char* index(const char*, int)',对于以下代码

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)”函数的一个函数*,但是什么是索引函数有什么作用? Google 似乎毫无用处,因为它提取了与 C++ 相关的书籍索引。

我对这个警告的解释是否遗漏了什么?

I'm removing all warnings from our compile, and came across the following:

warning: the address of `
char* index(const char*, int)', will always be 'true'

for the following line of code:

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

DEBUG_MSG is one of our logging macros that the preprocessor subsitutes into a statement that takes C++ style stream operations.

index does not appear to be declared, so I'm assuming that it was supposed to read:

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

and index would be a function* to the "char* index(const char*, int)" function in the standard library, but what does the index function do? Google seems useless as it pulls up indexes of books related to C++.

Is there something I'm missing in my interpretation of this warning?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等待圉鍢 2024-07-29 05:30:39

据推测,流运算符正在查看

<< index

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

<< (bool)index

但索引是一个函数,并且有一个永远不会为 NULL 的地址。 因此,这相当于:

<< true

G++ 认为这将始终为真,并发出警告。

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

Presumably, the stream operators are seeing

<< index

And attempting to automatically cast it into something that can be printed:

<< (bool)index

But index is a function, and has an address that will never be NULL. So this is equivalent to:

<< true

G++ sees that this will always be true, and issues a warning.

As for what index does, see http://www.linuxmanpages.com/man3/index.3.php

情域 2024-07-29 05:30:39

index中定义的函数已弃用,应替换为 strchr

index is a function defined in <strings.h> which is deprecated and should be replaced by strchr.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文