Addressing splint warnings about functions “not used” while they are passed as parameters

StackOverflow https://stackoverflow.com/questions/411726

  •  03-07-2019
  •  | 
  •  

Question

On a program of me, the splint checker warns:

expat-test.c:23:1: Function exported but not used outside expat-test: start
  A declaration is exported, but not used outside this module. Declaration can
  use static qualifier. (Use -exportlocal to inhibit warning)
   expat-test.c:38:1: Definition of start

The start() function is used. The program uses the expat XML parser which works with callbacks. You give the parser a function:

XML_SetElementHandler(parser, start, end);

and the parser calls it back at some points. This is a very common idiom in C and I wonder why splint complains. I find nothing in the FAQ or in the manual.

Was it helpful?

Solution

Do you call XML_SetElementHandler() in the same translation unit (normally the .c source file) in which start() is defined? If so, the warning might be correct: Add static to the function definition and check if your application still links without errors.

OTHER TIPS

The 'static' keyword effectively hides the name of a function from other translation units (.C file, usually). The code's still there, and from that C file you can get the address of the function (but not from other C files). You can then pass the address to other translation units, either by calling functions, or returning the address from a function, or by storing it in a global variable, etc.

I tend to declare all functions which are not being exported as static. I have been taught and currently believe that it is good practice to do so. (Disclaimer: As with most things, there are numerous exceptions to this 'rule'.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top