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!
-
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.
ojblass : But thats the point... if I put it into another file the warning goes away!?!?!?!??!Volte : splint's diagnosis is correct, within the context of its input (i.e. the only possible kind of correct for a computer program). The problem is that you are interpreting it as a dire warning rather than an observation that has been generated given the parameters given to it. You can ignore it safely. -
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
-
You might find that if you included a header that declared
flip()
- as you should, of course - thensplint
would not complain. You should also declareblah()
in the header as well.I'm not wholly convinced that this is the explanation because
blah()
is not used at all (though it usesflip()
) and you don't mentionsplint
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'.Bastien Léonard : +1, if a function is public it should be declared in a header, otherwise it should be static.ojblass : And you are right... forward declaring it in a header file shuts it up and it was complaining about blah as well.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.