在 IOKit 代码中使用 `decltype`

Using `decltype` in IOKit code

编译基于 IOKit 的内核扩展时,c++ 编译器无法识别关键字 decltype

int f = 123; 
int (*f_ptr)() = 0; 

f_ptr =  (decltype(f_ptr)) f;

上面的代码编译器失败,原因:Use of undeclared identifier 'decltype'。另一方面,auto 关键字按预期工作。

但是,如果我在 C++ 用户模式应用程序中编译完全相同的代码,它工作正常。

知道这是为什么吗?

decltype 需要 C++11 支持。查看您的项目 Build Settings 并确保 C++ Language Dialect 至少是 GNU++11/C++11 或更高版本(搜索 -std= 选项)

另一方面,

autoold storage duration specifier keyword re-used in C++11[6]。