与“index”相关的编译错误 - 它实际上是一个函数吗?
我正在从编译中删除所有警告,并遇到以下内容:
警告:`的地址 行将始终为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是索引的手册页:
http://kernel .org/doc/man-pages/online/pages/man3/index.3.html
Here's a man page for index:
http://kernel.org/doc/man-pages/online/pages/man3/index.3.html
据推测,流运算符正在查看
并尝试自动将其转换为可以打印的内容:
但索引是一个函数,并且有一个永远不会为 NULL 的地址。 因此,这相当于:
G++ 认为这将始终为真,并发出警告。
至于index的作用,请参见http://www.linuxmanpages.com/man3/index .3.php
Presumably, the stream operators are seeing
And attempting to automatically cast it into something that can be printed:
But index is a function, and has an address that will never be NULL. So this is equivalent to:
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
index
是中定义的函数
已弃用,应替换为strchr
。index
is a function defined in<strings.h>
which is deprecated and should be replaced bystrchr
.