Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it the case that the name of the function f4 has internal linkage, and not a C language linkage?

The fifth example in [dcl.link]/4 states the following:

extern "C" {
    static void f4(); // the name of the function f4 has internal linkage (not C language linkage)
                      // and the function’s type has C language linkage.
}

Why is this? Why is it the case that the name of the function f4 has internal linkage, and not a C language linkage?

P.S.: I'm asking this from a perspective of a language-lawyer. That is, how can one derive the commented statement above, from normative paragraphs in the Standard?

like image 484
Alexander Avatar asked Jul 27 '17 18:07

Alexander


People also ask

What is internal linkage and external linkage in C?

Internal linkage refers to everything only in scope of a translation unit. External linkage refers to things that exist beyond a particular translation unit. In other words, accessible through the whole program, which is the combination of all translation units (or object files).

What is the linkage of the function?

A linkage function is an essential prerequisite for hierarchical cluster analysis . Its value is a measure of the "distance" between two groups of objects (i.e. between two clusters).

Which keyword is used for internal linkage?

To use internal linkage we have to use which keyword? Explanation: static keyword is used for internal linkage.

What are the types of linkages a internal and external b external internal and none C external and none D internal?

Explanation: External Linkage-> means global, non-static variables and functions. Internal Linkage-> means static variables and functions with file scope. None Linkage-> means Local variables.


1 Answers

From that same section, emphasis mine:

In a linkage-specification, the specified language linkage applies to the function types of all function declarators, function names with external linkage, [...]

But, f4 is declared static, which means that name has internal linkage per [basic.link]/3:

A name having namespace scope has internal linkage if it is the name of:

  • a variable, function or function template that is explicitly declared static; or, [...]

Hence, the C linkage doesn't apply.

like image 75
Barry Avatar answered Oct 17 '22 17:10

Barry