Question

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?

Was it helpful?

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top