为什么模板函数不能具有extern“C”。连锁? [英] why can't a template function have extern "C" linkage?

查看:295
本文介绍了为什么模板函数不能具有extern“C”。连锁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切。


我可以看到一个函数直接从C调用的情况,

名称将会出现问题这个。


但是我看不出为什么模板函数不能给出extern的原因

" C"将它分配给C函数指针的链接。


Ian

解决方案

Ian< no***@nowhere.com>在新闻中写道:1122500290.491907@drone2-svc-

skyt.qsi.net.nz:

标题说明了一切。
名称将会填满这个。

但我看不出模板的原因功能不能给予外部
C将它分配给C函数指针的链接。

Ian




嗯......你的C程序怎么样(不会什么都不知道

模板)包括声明模板函数的头文件?

请记住模板函数实际上并不存在实例化了......(不确定实例化是正确的词......)


Andre Kostur写道:

[..]
请记住,模板函数在实例化之前实际上并不存在....(不确定实例化是否为正确的话....)




这是正确的词。


V


Andre Kostur写道:

Ian< no *** @ nowhere.com>在新闻中写道:1122500290.491907@drone2-svc-
skyt.qsi.net.nz:

标题说明了一切。
名称将会填满这个。

但我看不出模板的原因功能不能给予外部
C它被分配给C函数指针的链接。

Ian



嗯...你的C程序怎么样(不知道关于
模板的任何内容包括声明模板函数的头文件?
请记住,模板函数在实例化之前并不存在....(不是确定实例化是正确的词......)




正如我所说,我理解为什么这种情况不可能,但问题我

涉及为C驱动程序设置一些回调。驱动程序API有一个

的结构数,其中包含各种回调的函数指针。


因此在这种情况下,C函数指针将在C ++代码中赋值,模板实例化后,
。这些名字与C代码无关。


Ian


The title says it all.

I can see the case where a function is to be called directly from C, the
name mangling will stuff this up.

But I can''t see a reason why a template function can''t be given extern
"C" linkage where it is to be assigned to a C function pointer.

Ian

解决方案

Ian <no***@nowhere.com> wrote in news:1122500290.491907@drone2-svc-
skyt.qsi.net.nz:

The title says it all.

I can see the case where a function is to be called directly from C, the
name mangling will stuff this up.

But I can''t see a reason why a template function can''t be given extern
"C" linkage where it is to be assigned to a C function pointer.

Ian



Um... how would your C program (which doesn''t know anything about
templates) include the header file where the template function is declared?
Keep in mind that a template function doesn''t actually exist until it is
instantiated.... (not sure that "instantiated" is the right word....)


Andre Kostur wrote:

[..]
Keep in mind that a template function doesn''t actually exist until it is
instantiated.... (not sure that "instantiated" is the right word....)



It is the right word.

V


Andre Kostur wrote:

Ian <no***@nowhere.com> wrote in news:1122500290.491907@drone2-svc-
skyt.qsi.net.nz:

The title says it all.

I can see the case where a function is to be called directly from C, the
name mangling will stuff this up.

But I can''t see a reason why a template function can''t be given extern
"C" linkage where it is to be assigned to a C function pointer.

Ian


Um... how would your C program (which doesn''t know anything about
templates) include the header file where the template function is declared?
Keep in mind that a template function doesn''t actually exist until it is
instantiated.... (not sure that "instantiated" is the right word....)



As I said, I understand why this case can''t be, but the problem I had
involved setting up some callbacks for a C driver. The driver API has a
number of structs with function pointers for various callbacks.

So in this case, the C function pointers will be assigned in C++ code,
after the templates have been instantiated. the names are irrelevant to
the C code.

Ian


这篇关于为什么模板函数不能具有extern“C”。连锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆