When I compile C code in recent version of gcc, I am getting the following warning:
Function is define but not used.
What can be the reason for this warning and how can I approach to resolve it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As Giuseppe Guerrini mentioned, this is likely for a static function – you won’t see this warning on non-statics. The reason is that the compiler has to assume that a non-static function might be called from another compilation unit. however, a static function isn’t visible outside of the C file it’s in, so if it’s not used in that file, then it can’t be used at all.
If find myself generally irritated by these warnings because:
There are usually no negative side effects from having the function – even code space. Most linkers today will remove the code from the executable image if it’s not used.
I often define a function in anticipation of it being used, and the warnings cause the build to, well, emit diagnostics. I prefer my builds to be warning-free, but in these cases I’d like the function to be compiled – ready to use when the next bit of work is gotten around to.
I may have code that gets called only in debug builds, like in an assertion (or some conditionally compiled code). However, I’m not a huge fan of conditional compilation and like to reduce the use of
#ifstatements to as few as possible. So my preference would be to have those functions not conditionally compiled even if they only get called in a particular configuration.As far as I’m concerned there’s little use to the warning, and it’s probably OK to turn them off if you like. (I’d like to hear opinions that might change my mind…)