[prog] [C/C++] what to put in header files.

Sonja Krause-Harder skh at gmx.com
Wed Sep 18 21:01:43 EST 2002


Hi all,

I've finally started using C (and also C++) actively. As I'm still
far from fluent, I have a few questions, and the most puzzling
issue at the moment is the usage of header files.

My understanding is that a header file should contain everything
a "user" of my code needs to know without having to look at the
code itself. So I would have function prototypes, typedefs, structs
and (ouch) the odd global variable there.

To keep things tidy, I started to have a corresponding *.h for each
*.c file, and put every function prototype there. I also put all the
#include s I needed into the header file, and only #include this one
in the *.c file. While this is definitely neat and clean, it isn't
necessary all the time, and maybe a bit "chatty". Apart from that,
when I look at other projects, they don't usually do it that way, so
I'm wondering if there are some common rules how to organize
the header files, or if people are so used to grepping anyway that
it doesn't matter where to put things.

I'm completely confused by the way C++ programmers do that, as method
implementations turn up in header files quite often as well.

any insights appreciated,

Sonja

(Oh, and welcome to the list, all of you! ;-))



More information about the Programming mailing list