Linking and symbol visibility: “Names of functions in two different source files linked into one program must be unique.” Decide whether this statement is correct or incorrect.

Difficulty: Medium

Correct Answer: Incorrect

Explanation:


Introduction / Context:
This question focuses on linkage and symbol visibility in C programs. When multiple object files are linked together, external symbols with the same name clash. However, C also provides internal linkage using static to confine a function’s name to its translation unit.



Given Data / Assumptions:

  • We are talking about ordinary C functions compiled and linked into a single executable.
  • Two functions may share the same identifier if they have internal linkage (static) in separate files.
  • External linkage symbols must be unique within the final program.


Concept / Approach:
Function names with external linkage are visible across translation units and must be unique at link time. Declaring a function as static gives it internal linkage, meaning the symbol is private to that file; multiple files may each define a static function of the same name without conflict.



Step-by-Step Solution:
Case 1: extern (default) linkage in two files with same name → linker error (multiple definitions).Case 2: static linkage in each file → no collision; names are private to each file.Therefore, the blanket statement that names “must be unique” is incorrect.



Verification / Alternative check:
Build two files each containing “static void helper(void){}” and link; no error occurs. Change both to “void helper(void){}” and the linker reports multiple definitions.



Why Other Options Are Wrong:
Correct: misses the internal linkage case.Inline/debug: do not resolve linkage-conflict fundamentals.



Common Pitfalls:
Confusing storage class static with storage duration; overlooking the difference between declaration in headers (extern) and definitions in .c files.



Final Answer:
Incorrect

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion