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

后端 未结 7 815
青春惊慌失措
青春惊慌失措 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:16

    I wouldn't purposely put all my includes into a single header file, simply because if you change one of these included header files, you'll have to recompile everything that has included your "master" include file. This can lead to unnecessarily long compilation times for a single line change.

    That said, I wouldn't put too much time in making sure I'm not being too liberal with include statements. Some engineers will spend lots of time trying to reduce includes to save on compilation time, and I think their time is better served solving problems or working on new features.

提交回复
热议问题