有没有办法获取指针指向的数据类型?我对与 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/