Search code examples
cfunction-prototypes

Is it a good practice to always have function prototypes for static functions in C?


I am looking at some embedded firmware in C language. I notice there are static functions being used in .c files but there are no function prototypes. Is it a good practice to always put function prototypes near the top of the .c file? Are there situations when not putting function prototypes would be better?


Solution

  • Is it a good practice to always put function prototypes near the top of the .c file

    no. If using multiple .c files that are calling the same function, it would be better to declare that function in a .h file and include it, instead of redeclaring it in every new .c file that calls the function

    If using only one file, and you are not sure whether to declare it or not - declaring would enable you to call the function before its definition, so I think it would be good practice

    Are there situations when not putting function prototypes would be better?

    there are times in which you can compile without prototypes, but in general I think it's not better to omit them, but I don't think I can say it's really really bad