Topic: Trouble with extern "C" and template functions


Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1996/09/16
Raw View
rmashlan@r2m.com (Robert Mashlan) writes:

> Rune Huseby <rune.huseby@gpi.telemax.no> wrote:
>
> >The following (sample) program gives me this compiler error:
> >'second C linkage of overloaded function 'min' not allowed'
> >on the second call to min().
>
> >extern "C" void test(void)
> >{
> >  min(1, 2);  // Call with int
> >  min(1.0, 2.0);  // Call with double. Gives error
> >}
>
> It looks like you have uncovered a bug in the compiler.  There's no
> reason for min template to be generated as an extern "C" function.
> extern "C" should only apply to the linkage of the test function.  The
> test case compiles fine with BC++ 5.0, but it failed with VC++ 4.1.

While I agree with your analysis, and would like for it to be true, I'm
not sure what the current draft says for this case.  It all depends on
the "point of instantiation" of the template.

My impression is that the current draft specifies that the generated
functions in the above should use C++ linkage, but that the following
should be an error, because the generated functions should have C
linkage.

 extern "C" {
 void test()
 {
  min( 1, 2 ) ;
  min( 1.0 , 2.0 ) ;
 }
    }

I don't think it would be too much, even at present, to add text to the
effect that instantiations of a template function always have C++
linkage.  (But what about:

 template< class T > extern "Ada" f( T* pt ) ...

In this case, I want all of the expansions to be accessible from Ada.)

(I've cross-posted this to comp.std.c++, and set the follow-ups there.)


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]