| 2 |
raymond |
1 |
|
|
|
2 |
This directory is intended for project header files.
|
|
|
3 |
|
|
|
4 |
A header file is a file containing C declarations and macro definitions
|
|
|
5 |
to be shared between several project source files. You request the use of a
|
|
|
6 |
header file in your project source file (C, C++, etc) located in `src` folder
|
|
|
7 |
by including it, with the C preprocessing directive `#include'.
|
|
|
8 |
|
|
|
9 |
```src/main.c
|
|
|
10 |
|
|
|
11 |
#include "header.h"
|
|
|
12 |
|
|
|
13 |
int main (void)
|
|
|
14 |
{
|
|
|
15 |
...
|
|
|
16 |
}
|
|
|
17 |
```
|
|
|
18 |
|
|
|
19 |
Including a header file produces the same results as copying the header file
|
|
|
20 |
into each source file that needs it. Such copying would be time-consuming
|
|
|
21 |
and error-prone. With a header file, the related declarations appear
|
|
|
22 |
in only one place. If they need to be changed, they can be changed in one
|
|
|
23 |
place, and programs that include the header file will automatically use the
|
|
|
24 |
new version when next recompiled. The header file eliminates the labor of
|
|
|
25 |
finding and changing all the copies as well as the risk that a failure to
|
|
|
26 |
find one copy will result in inconsistencies within a program.
|
|
|
27 |
|
|
|
28 |
In C, the convention is to give header files names that end with `.h'.
|
|
|
29 |
|
|
|
30 |
Read more about using header files in official GCC documentation:
|
|
|
31 |
|
|
|
32 |
* Include Syntax
|
|
|
33 |
* Include Operation
|
|
|
34 |
* Once-Only Headers
|
|
|
35 |
* Computed Includes
|
|
|
36 |
|
|
|
37 |
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|