c++ - clang++ 是否忽略了一些弃用警告的 extern "C"?

标签 c++ multilingual clang++ extern-c

如果我用clang 3.8.1编译:

extern "C" {
int foo(int x) { register int y = x; return y; }
}

int main() { return foo(123); }

我收到警告:

a.cpp:3:18: warning: 'register' storage class specifier is deprecated and incompatible with C++1z [-Wdeprecated-register]
int foo(int x) { register int y = x; return y; }
                 ^~~~~~~~~

...我真的不应该得到这个,因为内部函数是 C 代码。如果我使用 GCC 6.3.1,即使使用 -Wall,我也不会收到此警告。

这是 clang 错误还是我做错了什么?

最佳答案

extern "C" 并不意味着“将此代码编译为 C”。它的意思是“使这个函数(或多个函数)可从 C 代码调用”,这通常意味着更改名称修饰,有时还意味着调用约定。

关于c++ - clang++ 是否忽略了一些弃用警告的 extern "C"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43474666/

相关文章:

c++ - 有没有办法在 Visual C++ 中编写带有变量参数列表的宏?

c++ - 查找两个数组中最接近的数字

c++ - 确认对 typedef 和 #define 的理解

Angular 4创建到同一组件的不同语言路径

php - 多语言数据库 : which method is better?

c++ - 在库中使用未定义的外部变量会在 macOS 中产生链接器错误

c++ - 错误 LNK1561 : entry point must be defined- main() exists

multilingual - 如何在 Kentico 中一次性为多个页面创建新的文化版本?

clang++ - 如何禁用 Clang 警告 "no case matching constant switch condition"

c++ - clang 认为我需要指向 "const function"吗?