user133466
user133466

Reputation: 3415

"We write a .h file for every module in our design" what is the module referring to?

"We write a .h file for every module in our design" what is the module referring to? and when do we write a separate .c file?

Upvotes: 0

Views: 281

Answers (2)

mingos
mingos

Reputation: 24512

It is generally a good idea to declare one class per header (.h or .hpp) and implement its content in one .cpp file. In case of C, you group the functions by what they do or the context they are used in and also declare them in one header and implement in one .c file. For instance: math, such as square roots, trigonometry stuff (sine, cosine, tangent), powers, perhaps also min/max functions (although they're beter off as macros in most cases) would reside in their very own .h/.c or .hpp/.cpp pair of files.

Of course, you can ignore this completely and stuff all your code in a single .c(pp) file, no header at all. It'll just become completely unreadable :).

Upvotes: 2

danben
danben

Reputation: 83270

A module is generally a unit of functionality, like a class or a set of functions. The .h file is just a header, containing method signatures, but no implementation. The implementation is found in the corresponding .c file.

At compile time, code that uses those functions only needs to import the header file; the implementation can be compiled separately and is linked afterwards in a linker step.

Edit: here is a link to the Wikipedia article on header files: http://en.wikipedia.org/wiki/Header_file

Upvotes: 1

Related Questions