Most of the time in C programming it seems that there will be one header file (.h) per code file (.c), for the function prototypes at least.
When would it be appropriate to not have a header file for a code file?
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.
There’s a few use cases for this. The most obvious is that your main program rarely needs a header file.
The second is where you don’t have one header for each C file. I’ve put together libraries before (let’s say a BTree library for the purposes of this answer) where each individual function is in its own source file but there’s a library-wide header file, something like:
and so on. The private header file is for stuff that need to be shared between the code but is not to be published in the API.