Can be declared multiple times, but cannot be defined multiple times
For a project, we should handle a lot of. C and. H files.
1. Use the header file to call the library function: # include <stdio. h> in many cases, the source code is inconvenient (or inaccurate) to be published to the user. You only need to provide the header file and binary Library to the user.
2. Manually defined. h file: # include "avformat. H"
It generally provides struct declaration or definition, function declaration, enumeration declaration or definition, macro variable definition, etc.
The definition is implemented in the. c file.
Two custom cases:
1.
2.
Assume that the compiled program is compiled
D. C (When Main () is included, it is found to include
A. H (If a function is declared, the compiler will follow the predefined path (
Include path list and code file path)Find the function definition. 1. Find the same name in the current directory
A. cFile, find the function definition, and continue to compile. 2. Find the same name in the current directory
A. cFile, where the function definition is not found, and then find
A. cThe. c file corresponding to other. H files in the File Include. If the function definition is found, continue to compile. 3. The file with the same name is not found in the current directory
A. cFile, search for. other include in H. h file to the corresponding. c file. If the function definition is found, continue compiling. 4. if this function definition is not found, a compilation error is returned.
The include process can be regarded as a process of file splicing.
If you want to know the search process, you should understand the working principle of the compiler.
In a project. the H file is referenced multiple times. the H file will be put into multiple files. if the c file is compiled multiple times, we should try to avoid such multiple declarations. to improve efficiency.
The above D. H file will repeat the declaration of two int A ();, so it will be a bit repetitive, then the Conditional compilation Macro will come in handy.
In this way, the definition will not be repeated.