I am trying to understand compiling process in terms of a simple c++ program as follows:
#include<iostream.h>
#include<conio.h>
#include<math.h>
#define sum(a,b) a+b
int a;
void main()
{
int b;
cin>>a>>b;
cout<<"hello"<<endl;
cout<<pow(a,2)<<endl;
cout<<sum(a,b);
getch();
}
My understanding so far:
1) Preprocessing: All macros are expanded and expressions are substituted. eg: sum(a,b). Function prototypes of all functions we are using the program, are added to the code. eg: pow() function from math.h
2) Compiling: The preprocessed code is converted to assembly code and then into a single object code(this is in machine language).
3) Linking: Decides how the memory should be allocated to various sections of the code - Global (int a) and local variables (int b).
In case of static linking, Function definitions from various header files are added to the code too. eg: Definition of pow() from math.h. Finally one standalone single executable file is generated.
In case of dynamic linking, function definitions are not added. Finally one single executable file is generated, but it is not standalone.
Is my understanding wrong ? What am I missing ?