Alex Rivera | Logout

Header per source file

Asked 2009-07-22T20:02:16.147
17

I'm trying to understand the purpose behind one header per each source file method. As I see it, headers are meant for sharing function declarations, typedef's and macro's between several files that utilize them. When you make a header file for your .c file it has the disadvantage that each time you want to see a function declaration or macro you need to refer to the header file, and generally it is simpler that everything is in one source file (not the whole software, of course).

So why do programmers use this method?

Edit
Report

2 Answers

1

You don't need one header per source file. One header per module, containing the public interface, and maybe an additional header containing private declarations etc shared between files in that module.

answered 2009-07-22T20:09:30.063
0

Generally a header for a source file method means that you declare only the functions from that compilation unit in that header.

That way you don't pollute with declarations you don't need. (in large software project might be a problem)

As for separate compilation units, these speed up the compilation and can help you avoid collisions if private symbols are declared static.

answered 2009-07-22T20:06:31.893

Your Answer