Brian
Brian

Reputation: 895

How to find the include path for string.h in xcode

I am getting sick of seeing the warning

"Declaration of 'index' shadows a global declaration"

index is defined in string.h. I don't think that it's required for anything I am using and I really don't want to change all the local vars from index to something else.

Anyone know of a way to find out how (by what path) string.h is included? Is it possible to prevent it from being included?

Upvotes: 0

Views: 1677

Answers (2)

Stephen Canon
Stephen Canon

Reputation: 106227

The index function is actually declared in /usr/include/strings.h, and is marked as removed as of POSIX issue 7. You can hide its declaration by setting the appropriate POSIX version with the compiler flag -D_POSIX_C_SOURCE=200809. This will also hide other functions deprecated in issue 7, like bcopy and bzero.

Upvotes: 2

Justin Spahr-Summers
Justin Spahr-Summers

Reputation: 16973

I find -Wshadow extremely annoying and rarely useful. Even if you solve this one case, there are bound to be others in the future, especially since system headers may define non-standard functions and variables which yours unintentionally shadow.

Personally, I would just disable the warning, and manually make sure no variables, functions, etc. are named the same as something being used.

Upvotes: 0

Related Questions