c语言头文件解析(C language header file parsing)
c语言头文件解析(C language header file parsing)
C language.H and.C file analysis (2010-03-11 18:07:37) reprint labels: Gossip
Simple said that in fact to understand the C file and header files (.H) what is different, first need to understand the working process of the compiler, the compiler will generally do the following:
1. preprocessing
2. lexical and syntax analysis phase
The 3. compilation stage, first compiled into pure assembler statements, then compiled with CPU binary code, to generate the target file (.Obj file)
The 4. connecting stage, each section of each code in the object file for the absolute address generation, associated with platform specific executable file, of course, also can generate pure binary code with objcopy, is to remove the file format information. (.Exe file)
The compiler at compile time is based on the C file as a unit, that is to say if a C file in your project are not, then your project will not compile to the target file connector is for the unit, it will carry out re positioning function and variable of one or more of the target file, generate the final the executable program, developed in PC, generally have a main function, this is the compiler agreed, of course, if you write the linker script yourself, you can not main function as the entrance program!!!!
(main.C file object file executable file)
With these basic knowledge, and so, in order to create a final executable file, you need some of the target file is C file, C file and the entrance to a main function as the executable program, then we start from a C file, if the contents of the C file the following:
#include
#include "mytest.h"
Int main (int argc, char **argv)
{
Test = 25;
Printf ("test.................%d\n, test);
}
The header file as follows:
Int test;
Now in this example to explain the compiler work:
1. preprocessing stage: the compiler in C file as a unit, first read the C file, find the first sentence and the second sentence contains a header file, will find the