views:

114

answers:

3

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?

+3  A: 

Here's a man page for index:

http://kernel.org/doc/man-pages/online/pages/man3/index.3.html

Michael
Thanks, this solidifies what's going on, and that it's not what the original user intended.
Luciano
A: 

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

Dario
+1  A: 

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

bdonlan