What's the role of a linker in modular programming?

A linker in modular programming combines separate program modules into a single program for execution.

In the realm of modular programming, a linker plays a pivotal role. It is a system program that takes one or more objects generated by compilers and combines them into a single executable program. This process is known as linking. The linker resolves references to undefined symbols, assigns absolute addresses to relocatable symbols, and revises the target code to reflect these addresses.

Modular programming is a software design technique that emphasises separating the functionality of a program into independent, interchangeable modules. Each module is a separate unit of the software that can be independently created and tested. This approach increases the maintainability and reusability of the code, as modules can be debugged separately or shared among different programs.

The linker comes into play when these separate modules need to be combined into a single executable program. It takes care of the task of stitching together the object code from each module. It also resolves any references between the modules. For instance, if one module calls a function defined in another module, the linker ensures that the call will correctly reach the intended function when the program is run.

Moreover, the linker assigns memory addresses to each module. In the compilation phase, each module is compiled separately, and the compiler typically starts addressing at zero for each module. The linker adjusts these relative addresses to absolute addresses in the final program memory space.

In summary, the linker is a crucial component in modular programming. It enables the benefits of modular programming by allowing separate modules to be combined into a single executable program, resolving inter-module references, and assigning absolute memory addresses. Without the linker, the modular programming approach would not be feasible, as the separate modules could not be combined into a runnable program.

Study and Practice for Free

Trusted by 100,000+ Students Worldwide

Achieve Top Grades in your Exams with our Free Resources.

Practice Questions, Study Notes, and Past Exam Papers for all Subjects!

Need help from an expert?

4.93/5 based on525 reviews

The world’s top online tutoring provider trusted by students, parents, and schools globally.

Related Computer Science a-level Answers

    Read All Answers
    Loading...