c - 编译时指针指向的类型如typeof

标签 c gcc clang

有没有办法获取指针指向的数据类型?我对与 typeof 类似的东西很感兴趣。我希望我能用一段代码更好地解释它:

struct_t *pointer1;
struct_t **pointer2;
typeof_ptr(pointer) a;  // here a should be of type struct_t
typeof_ptr(pointer) b;  // here b should also be of type struct_t

最佳答案

您可以执行 typeof(*pointer1),但 typeof(*pointer2) 将是 struct_t* 而不是 struct_t;你需要做 typeof(**pointer2)

请记住 typeof() 是 GCC 扩展。

关于c - 编译时指针指向的类型如typeof,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49581886/

相关文章:

macos - 在 CodeRunner 中编译时出现 Clang 错误

c - 警告 : comparison is always true due to limited range of data type

c++ - 通过 C++ 编译器构建 C 应用程序

c++ - 使用 PyTorch、HElib 和 OpenCV 编译 C++ 程序时出现问题

macos - 如何在 Mac OS X 10.8 上编译 FreeImage?

c++ - 为什么 gcc 和 clang 都不发出任何警告?

c++ - 我如何使用 cryptimportkey 函数导入私钥来加密数据相同的结果使用导入的 key

c - 在 C 中转义 char *

c++ - 函数参数的 Visual Studio 缩进

c - 如何使用堆栈帧访问函数的第一个参数?