Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

header-files

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 file?

What about includes that are used in practically every file (i.e. stdio.h)?

like image 506
danpker Avatar asked Feb 28 '11 04:02

danpker


1 Answers

No. It simply adds cruft and overhead.

One of the biggest pains that you'll face as a maintainer is figuring out what headers don't need to be included and get rid of them. Whe you get to a list of 20+ headers, you start contemplating ugly things like brute forcing through it (removing one at a time and seeing if anything breaks).

Be kind to people who have to maintain your stuff in the future. Use the headers you need per module, no more .. no less :)

like image 185
Tim Post Avatar answered Oct 22 '22 08:10

Tim Post