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 – thensplintwould 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 mentionsplintcomplaining about that.However, it is a good practice to make every function (in C)
staticuntil 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’.