Addressing bus warnings about "not used" functions while they are passed as parameters

In my program, 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 an expat XML parser that works with callbacks. You give the parser a function:

XML_SetElementHandler(parser, start, end);

      

and the parser calls it at some points. This is a very common idiom in C and I wonder why bus is complaining. I didn't find anything in the FAQ or in the manual .

0


source to share


3 answers


Are you calling XML_SetElementHandler()

in the same translation unit (usually the .c source file) that defines start()

? If so, the warning might be correct: add static

to the function definition and check if your application is not linked without errors.



+2


source


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



+2


source


I tend to declare all functions that are not exported as static. I have been taught and now believe that this is good practice. (Disclaimer: As with most things, there are many exceptions to this "rule".)

0


source







All Articles