C language linkage: Which types of linkages are recognized for identifiers in C—considering scope and visibility across translation units?

Difficulty: Easy

Correct Answer: External, Internal and None

Explanation:


Introduction / Context:
In C, linkage describes whether multiple declarations refer to the same entity across scopes and translation units. Understanding linkage is key to organizing headers and source files, avoiding multiple-definition errors, and intentionally restricting visibility of symbols.


Given Data / Assumptions:

  • We are discussing identifiers with potential external visibility (functions, global objects) and those restricted to a translation unit or block.
  • Storage-class specifiers like 'static' and 'extern' affect linkage.
  • Block-scope variables generally have no linkage.


Concept / Approach:

  • External linkage: The identifier refers to the same entity across translation units (e.g., non-static functions/globals).
  • Internal linkage: The identifier is limited to a single translation unit (e.g., 'static' global objects or functions).
  • No linkage: Each appearance refers to a distinct entity (e.g., block-scope variables, function parameters, typedef names).


Step-by-Step Solution:

Map examples to linkage: 'int g;' (external), 'static int g;' (internal), 'int x' inside a block (no linkage).Recognize that all three categories exist in the language standard.Therefore, the correct choice is 'External, Internal and None'.


Verification / Alternative check:

Link two files that declare the same non-static function → they refer to one function (external). Make a function 'static' → calls from another file fail (internal). Local variables of the same name in different functions are independent (no linkage).


Why Other Options Are Wrong:

  • Pairs or singletons omit one or two categories defined by the standard.
  • Only External/Internal: ignores block-scope identifiers with no linkage.


Common Pitfalls:

  • Confusing storage duration (automatic/static) with linkage (external/internal/none).
  • Assuming 'extern' always defines; it usually only declares for objects.


Final Answer:

External, Internal and None

More Questions from Declarations and Initializations

Discussion & Comments

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