C47. C Header Files

Header Files
When we divide a program into several source files, problems arise: How can a function in one file call a function that's defined in another file? How can a function access an external variable in another file? How can two files share the same macro definition or type definition? The answer lies with the #include directive, which makes it possible to share information—function prototypes, macro defini­tions. type definitions, and more—among any number of source files.
The #include directive tells the preprocessor to open a specified file and insert its contents into the current file. Thus, if we want several source files to have access to the same information, we'll put that information in a file and then use #include to bring the file's contents into each of the source files. Files that are included in this fashion are called header files (or sometimes include files): I'll discuss them in more detail later in this section. By convention, header files have the extension . h.
Note: The C standard uses the term "source file" to refer to all files written by the programmer, including both .c and .h files. I'll use "source file" to refer to . c files only.

No comments: