1. Connector
C language has the idea of compiling separately, that is, dividing a C language project into several sources.ProgramLet them compile separately at different times, and then integrate them together at appropriate times. The integration process is completed by the connector.
Most of the time, the connector and compiler are separated, and the connector itself does not understand many C language syntax rules. Because he is generally not in direct contact with C, we think about the C language compilation and running process, the responsibility of the compiler is to translate the C language into a form that the connector can understand.
The connector integrates several target modules generated by the compiler into a load module or an executable file that can be directly executed by the operating system.
The connector also handles naming conflicts. The connector generally regards the target module as a group of external objects. Each external object represents a part of the machine's memory and is identified by an external name. Therefore, when functions and variables are not declared as static, they are regarded as an external object. There are also some compilers that perform special processing on a static declared variable name, and then treat it as an external object.
2. Let's talk about extern.
In fact, extern is also the connector's credit. For example, extern int I; In the connector's opinion, this is a declaration, not a definition. This declaration means that he does not need to allocate space for it, instead, it looks for references to an external object with the same name in other programs.
Therefore, an extern reference must be included in this project. If the program contains two definitions, the general compiler reports an error. The best way is to write the extern definition in a uniform header file. When an external variable is required, reference this header file.