Search code examples
cfunction-prototypes

How to find C functions without a prototype?


Company policy dictates that every function in C source code has a prototype. I inherited a project with its own make system (so I cannot test it on gcc or Visual Studio) and found that one of the files has some static functions declared without prototypes. Is there a way (not necessarily with a compiler) to list all functions without prototypes in all .c files?


Solution

  • gcc has an option to warn you about this:

    gcc -Wmissing-prototypes
    

    You can turn this warning into an error to stop compilation and force people to fix it:

    gcc -Werror=missing-prototypes
    

    If you just want to list it you can compile with the gcc option -Wmissing-prototypes and grep for no previous prototype for in the log.

    Update based on edit:

    Since you now mention that you can't use gcc, you'll have to find a similar option for your current compiler. Most compilers have such an option. Start with the man page or the built in help output.