Title
Linkage of locally declared functions
Status
cd1
Section
9.11 [dcl.link]
Submitter
Mike Ball

Created on 1998-03-19.00:00:00 last changed 196 months ago

Messages

Date: 2002-10-15.00:00:00

[Moved to DR at October 2002 meeting. This was incorrectly marked as having DR status between 4/01 and 4/02. It was overlooked when issue 4 was moved to DR at the 4/01 meeting; this one should have been moved as well, because it's resolved by the changes there.]

Date: 2001-04-15.00:00:00

Proposed Resolution (04/01):

See the proposed resolution for Core issue 4, which covers this case.

The ODR should also be checked to see whether it addresses name and type linkage.

Date: 2022-02-18.07:47:23

Consider the following:

    extern "C" void foo()
    {
        extern void bar();
        bar();
    }
Does "bar()" have "C" language linkage?

The ARM is explicit and says

A linkage-specification for a function also applies to functions and objects declared within it.
The DIS says
In a linkage-specification, the specified language linkage applies to the function types of all function declarators, function names, and variable names introduced by the declaration(s).
Is the body of a function definition part of the declaration?

From Mike Miller:

Yes: from 9.1 [dcl.pre] paragraph 1,

    declaration:
      function-definition
and 9.5 [dcl.fct.def] paragraph 1:
    function-definition:
      decl-specifier-seqopt declarator ctor-initializeropt function-body
At least that's how I'd read it.

From Dag Brück:

Consider the following where extern "C" has been moved to a separate declaration:

    extern "C" void foo();

    void foo() { extern void bar(); bar(); }
I think the ARM wording could possibly be interpreted such that bar() has "C" linkage in my example, but not the DIS wording.

As a side note, I have always wanted to think that placing extern "C" on a function definition or a separate declaration would produce identical programs.

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2003-04-25 00:00:00adminsetstatus: dr -> wp
2002-11-08 00:00:00adminsetmessages: + msg772
2002-11-08 00:00:00adminsetstatus: ready -> dr
2002-05-10 00:00:00adminsetstatus: dr -> ready
2001-05-20 00:00:00adminsetmessages: + msg517
2001-05-20 00:00:00adminsetstatus: drafting -> dr
1998-03-19 00:00:00admincreate