Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 extern “C” 的描述,是不严谨,乃至错误的。 #114

Open
Mq-b opened this issue Nov 7, 2023 · 2 comments
Open

关于 extern “C” 的描述,是不严谨,乃至错误的。 #114

Mq-b opened this issue Nov 7, 2023 · 2 comments

Comments

@Mq-b
Copy link

Mq-b commented Nov 7, 2023

描述的是:

extern “C”

  • 被 extern 限定的函数或变量是 extern 类型的
  • 被 extern "C" 修饰的变量和函数是按照 C 语言方式编译和链接的

不管是第一句话还是第二句话,都是既不严谨,也错误的。
并且我严重怀疑抄了知乎的一篇文章,描述简直一模一样。

  1. “是 extern 类型的”,这话很莫名其妙,extern 不是类型。
    非要狡辩一下那就是,写的时候想着:“语言链接是每个函数类型的一部分”;但也和 extern 没关系。
  2. 这个能扯的其实很多,按照语言层面的标准回答,使用文档的描述最为合适:"C",可以与使用 C 程序语言编写的函数进行链接,使得在 C++ 程序中定义能从 C 单元调用的函数成为可能。 标准并不在乎是如何做到的,如果还要讲,那就是符号修饰,等等。不同平台,不同编译器,即使都使用了 extern "C" 符号修饰也不一定一样,C 标准不存在 ABI,有兴趣可以自己了解。
@boolsatellite
Copy link

应该是命名倾轧问题

@Mq-b
Copy link
Author

Mq-b commented Nov 11, 2023

啥意思,命名倾轧
@boolsatellite

Mq-b added a commit to Mq-b/interview that referenced this issue Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants