一些lib:
voID register_callback(voID (*cb)()){ .. cb(); ..}
主程序
namespace {int foo_cb() { ... } // internal linkage}int main(){ register_callback(foo_cb);}解决方法 TL; DR:是的,没关系
来自[basic.link](强调我的):
A name is saID to have linkage when it might denote the same object,
When a name has internal linkage,the entity it denotes can be
reference,function,type,template,namespace or value as a name
introduced by a declaration in another scope:
referred to by names from other scopes in the same translation unit.[…]
An unnamed namespace or […] has internal linkage. […]. A name having namespace scope that has not been
a function; or
given internal linkage above has the same linkage as the enclosing
namespace if it is the name of
所以基本上,链接是名称的属性而不是对象,函数等的属性.这意味着在未命名的命名空间内声明的函数不能通过名称从另一个转换单元调用.用它的指针调用它是没有限制的.
总结以上是内存溢出为你收集整理的c – 通过来自另一个翻译单元的指针调用具有内部链接的函数全部内容,希望文章能够帮你解决c – 通过来自另一个翻译单元的指针调用具有内部链接的函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)