Should a function prototype always be in its header file?

Viewed 4446

Lets say we have a few C source files such as file1.c, file2.c and main.c. We have functions as:

file1.c
      |---> file1Func1()
      |---> file1Func2()

file2.c
      |---> file2Func1()
      |---> file2Func2()

and the main file uses these functions. Now it would be natural that I create and add respective function prototype in header files file1.h and file2.h, then include these headers in main.c to use the functions.

What if I have a very large project with over thousand source (C) files, should I always create a header (then add function prototype) for every source file. Then include the header to use the functions?

Or using extern for using a function defined elsewhere (in some other source file) and rely on linker to search and fetch the function from the object file during link time?

Note: using the latter approach triggers MISRA warning of no function prototype.

3 Answers
Related