Tutorial :How does splint know my function isn't used in another file?


Splint gives me the following warning:

encrypt.c:4:8: Function exported but not used outside encrypt: flip    A declaration is exported, but not used outside this module. Declaration can    use static qualifier. (Use -exportlocal to inhibit warning)     encrypt.c:10:1: Definition of flip  

Since I called splint only on this file how does it know that?

#include        <stdio.h>  #include        <stdlib.h>    int    flip( int a)  {          int b;          b = a;          b ^= 0x000C;          return b;  }    int     blah(int argc, char    *argv[]) {            FILE    *fp = NULL, *fpOut=NULL;          int             ch;          ch = 20; flip(20); return (ERROR_SUCCESS);  }  

I even got rid of main so that it could not figure out that the file is complete in any way. I am totally stumped!


You might find that if you included a header that declared flip() - as you should, of course - then splint would not complain. You should also declare blah() in the header as well.

I'm not wholly convinced that this is the explanation because blah() is not used at all (though it uses flip()) and you don't mention splint complaining about that.

However, it is a good practice to make every function (in C) static until you can demonstrate that it is needed outside its source file, and then you ensure that there is a header that declares the function, and that header is used in the file that defines the function and in every file that uses the function.

In C++, the 'every function should be static' advice becomes 'every function should be defined in the anonymous namespace'.


Since I called splint only on this file how does it know that?

You have answered your question. You've fed in one file to lint, so lint knows there is only file to be taken care of (apart from the standard header includes, of course).


int flip() is not declared as static, so it can be potentially used externally. Since you invoked splint with only one source file, it correctly says that your function, if not used externally, must be declared static


It can only report on what it sees. Ignore the warning or follow the instructions to inhibit it if you know better than what it says. Don't assume that a tool like this necessarily knows your program better than you do.

If it really is not intended to be used outside of the file, you can declare it static and it should correct the problem, but it will be inaccessible from other files.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »