<>1. The process of generating an executable program

stay C/CPP in , Generating executable programs requires preprocessing , compile , assembly , Link four processes

<>1.1 Pretreatment

Pretreatment stage :

* Expand header file , Macro replacement , Conditional compilation , Remove comments
* generate .i file
<>1.2 compile

* Check syntax
* Generate assembly code
* generate .s file
<>1.3 assembly

Assembly phase :

* Convert assembly code into binary machine code
* Generate a symbol table for this file
* generate .o file

<>1.4 link

link :

* Consolidated segment table
* Summary symbol table , Find the address of the calling function , Link correspondence , Merge together
* Put all .o Files and static libraries , Dynamic libraries are linked together to generate executable programs
<>2.CPP Treatment of

Why? cpp Function overloading is not supported c Language does not support function overloading ?

Through the generation process of executable files, we know , We know that in the compilation process , The mapping relationship between function name and function address will be recorded in the symbol table .
// Take the following simple program as an example void f(int a,double b) { printf("%d %f",a,b); } void f(double b,
int a) { printf("%f %d",b,a); }
View the symbol table corresponding to the function

It can be concluded that cpp The function name in the assembly is :

Z Function name length Function name Parameter type initials 1, Initials 2…

<>3.C Language processing
// Take the following procedure as an example void f(int a,int b) { printf("%d %d",a,b); } void func(int c,int d)
{ printf("%d %d",c,d); }
View symbol table

C In language symbol table , The address of the function also corresponds to the function name , however C The function name of the symbol table in the language does not contain parameter types , Function name length information .

This also explains C Why doesn't the language support function overloading . Because when the same function name is defined , An error occurred while summarizing the symbol table . So this kind of error occurs in the assembly stage

<>4.CPP Type of function overload

In symbol table , Function name and address correspond one by one . and CPP The function name in the symbol table is :Z Function name length Function name Parameter type initials 1, Initials 2…

So the types of function overloading are :

* Parameters of function ; Different types
* The order of function parameters is different
* The number of function parameters is different

Technology