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)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 🙂