Is it a good idea to put all of your includes in one header file?

后端 未结 7 759
青春惊慌失措
青春惊慌失措 2021-01-04 21:08

What is the best practice for C what you put into a C header file?

Is it useful to put all the includes used for a program across multiple source files in one header

7条回答
  •  时光说笑
    2021-01-04 21:28

    Some things not already pointed out:

    • unneeded dependancies add to the compile time. When you modify an header, you'll have to recompile all compilation units which include it directly or indirectly. If the inclusion is not needded, the recompilation isn't either. The larger your program is, the bigger will be the problem, especially if you have broken your programs into composants whose recompilation your have to trigger manually.

    • pre-compiler headers may be more efficient when you add unneeded dependencies.

提交回复
热议问题