gpt4 book ai didi

c++ - extern "C"函数访问代码

转载 作者:太空宇宙 更新时间:2023-11-04 05:44:42 25 4
gpt4 key购买 nike

假设我有以下 C++ 代码:

int x;
some_class y;

extern "C" {
void foo () {
// do something with x
// do something with y
}
}

x 和/或 y 是否需要用 extern "C" 声明?

最佳答案

没有。 extern "C" 函数访问具有 C++ 语言链接的函数和变量没有限制。

C++ extern "C" 函数通常用于为具有 C++ 语言链接的代码提供 C 接口(interface),因此如果是这种情况,它会受到更多限制。

关于c++ - extern "C"函数访问代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8811273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com