<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 29</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="29"></A><H4>29.
  
Linkage of locally declared functions
</H4>
<B>Section: </B>9.12&#160; [<A href="https://wg21.link/dcl.link">dcl.link</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD1
 &#160;&#160;&#160;

 <B>Submitter: </B>Mike Ball
 &#160;&#160;&#160;

 <B>Date: </B>19 Mar 1998<BR>



<P>[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 <A HREF="4.html">issue 4</A> 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.]</P>



<P>Consider the following:</P>
<PRE>
    extern "C" void foo()
    {
        extern void bar();
        bar();
    }
</PRE>
Does "bar()" have "C" language linkage?

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

<P><U>From Mike Miller:</U></P>

<P>Yes: from 9.1 [<A href="https://wg21.link/dcl.pre#1">dcl.pre</A>] paragraph 1,
</P>
<UL>
<I>declaration:</I>
<UL><I>function-definition</I></UL>
</UL>
and 9.6 [<A href="https://wg21.link/dcl.fct.def#1">dcl.fct.def</A>] paragraph 1:

<UL>
<I>function-definition:</I>
<UL><I>decl-specifier-seq<SUB>opt</SUB> declarator ctor-initializer<SUB>opt</SUB>&#160;function-body</I></UL>
</UL>
At least that's how I'd read it.

<P><U>From Dag Br&#252;ck:</U></P>

<P>Consider the
following where extern "C" has been moved to a separate declaration:</P>
<PRE>
    extern "C" void foo();

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

<P>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.</P>

<P><B>Proposed Resolution (04/01):</B></P>

<P>See the proposed resolution for
<A HREF="4.html">Core issue 4</A>, which covers this case.</P>

<P>The ODR should also be checked to see whether it addresses name and
type linkage.</P>
<BR><BR>
</BODY>
</HTML>
