Search code examples
clanguage-lawyerdefinitionidentifierlinkage

How does external / internal identifier relate to the linkage?


C2x (and before) uses the following terms w/o a definition: "external identifier" and "internal identifier".

How do these terms relate to the linkage?

Logically:

  • "external identifier" == "identifier with external linkage"
  • "internal identifier" == "identifier with internal linkage OR identifier with no linkage"

Is that correct?


Solution

  • C17 uses the term "external identifier" in these places (exhaustive list):

    • Paragraph 5.2.4.1/1 requiring that a conforming implementation be able to translate and execute at least one program containing at least 31 significant initial characters in an external identifier.

    • Footnote 72 to paragraph 6.4.2.1/3, discussing the semantics and handling of extended characters in identifiers on systems whose linkers cannot accept extended characters. On such systems, "Extended characters may produce a long external identifier."

    • Paragraph 7.16.1/1, about potential name collisions with the va_* variadic-argument access macros / functions.

    • Paragraph 7.17.1/6, about potential name collisions with the generic functions declared in stdatomic.h.

    • Paragraph J.1/1, referring back to section 5.2.4.1

    • Paragraph J.2/1, referring to undefined behavior described in section 7.13 in the event that "the program defines an external identifier with the name setjmp."

    • Paragraph J.2/1, referring to section 7.16

    All of those are about linkage -- that is, the association of identifiers with the objects or functions -- not about (say) the lexical context of the identifier's declaration.

    Furthermore, although the specification does not explicitly define "external identifier", it does, in paragraph 6.4.2.1/5, define "external name" as "identifier that has external linkage". It also uses the word "name" as a synonym for "identifier" in several places, generally in the context of function names.

    I have every reason, then, to take "external identifier" to be synonymous with "external name" and "identifier with external linkage". The main alternative would seem to be "identifier declared in an external declaration", but it makes little sense that some of the particular provisions related to external identifiers should apply only to identifiers appearing in external declarations and not to identifiers declared at block scope with external linkage.


    The term "internal identifier" appears only once in C17, in paragraph 5.2.4.1/1, requiring that a conforming implementation be able to translate and execute at least one program containing at least 63 significant initial characters in an internal identifier. This is parallel to one of the appearances of "external identifier", and, also parallel to "external identifier", there is a definition the related term "internal name": "a macro name or an identifier that does not have external linkage" (paragraph 6.4.2.1/5).

    Similarly to the case with "external identifier", then, I take "internal identifier" to be synonymous with "internal name": an identifier that does not have external linkage. Another way to say that would be an identifier with internal linkage or no linkage.