in c/c++ program:
1. The differences between symbol relocation and symbol resolution.
2. Why is it a good idea to have multiple object files as opposed to just one?
3.
1. Answer: Difference between Symbol relocation vs Symbol Resolution
Symbol resolution: Symbol resolution means to find the definition of undefined reference in an object file.
Ex: let say we have two file main.c and swapnumber.c
main.c
int num[2] = {5,6};
int main(){
swapnumber();
}
The use of swapnumber() in main.o needs to be resolved to definition found in swapnumber.o
Symbol relocation: It is a process of assigning an absolute address to the code and data.
Ex: swapnumber.c
extern int num[];
void swapnumber(){
int temp;
temp = num[1];
int num[1] = num[0];
num[0] = temp;
}
here swapnumber.c compiled without knowing about num, it is the responsibility of the linker to allocate memory and update uses of num in swapnumber.o to use this location.
2. Answer: Multiple objects file optimize the performance of a compiler. The separate unit compilation is faster than a single object file. Let say we are working on a large project and we did a few changes in the code of the project than we need to compile the entire file and a new object file will be created. This makes the compiler slow. If we have multiple object files of a large project than if we change the code in one of the files, then it is easy to create an object of the smaller file rather than a whole project at once.
Get Answers For Free
Most questions answered within 1 hours.