. C and. H files

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.