Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

ctags can do that!

--c-kinds=p generates the list of all function prototypes

--c-kinds=f generates the list of all function definitions

Now you just need to compare those.

diff -u <(ctags -R -x --sort=yes --c-kinds=f | cut -d' ' -f1) <(ctags -R -x --sort=yes --c-kinds=p | cut -d' ' -f1) | sed -n 's/^-//p'

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top