Consider a program P that consists of two source modules M1 and M2 contained…

2004

Consider a program P that consists of two source modules M1 and M2 contained in two different files. If M1 contains a reference to a function defined in M2, the reference will be resolved at

  1. A.

    Edit-time

  2. B.

    Compile-time

  3. C.

    Link-time

  4. D.

    Load-time

Attempted by 388 students.

Show answer & explanation

Correct answer: C

Answer: Link-time

Explanation: When modules are in separate source files, each file is compiled separately into an object file. The actual matching of an undefined function reference in one object file to the function definition in another object file is performed by the linker.

  • Compile-time — the compiler checks declarations, types, and generates object code for each translation unit, but it does not resolve addresses of symbols defined in other files.

  • Link-time — the linker combines object files and libraries and resolves symbol references between them. This is where cross-file references (like a call in one module to a function in another) are resolved.

  • Load-time — the dynamic loader can resolve symbols for shared libraries when a program is loaded; this applies to dynamic linking rather than the typical static link of separate object files.

  • Edit-time — the editor or IDE may assist with navigation or autocomplete, but it does not perform formal symbol resolution for building the program.

Example: M1 includes a declaration (via a header) and calls a function defined in M2. The compiler compiles M1 and M2 into object files; the linker then matches the undefined symbol in M1's object file to the definition in M2's object file and resolves the reference.

Takeaway: For separate source files, symbol resolution across files happens at link-time. Dynamic linking can shift some resolution to load-time or runtime, but the standard cross-file binding is performed by the linker.

Explore the full course: Gate Guidance By Sanchit Sir