假设有一个 API,如下所示:
void myAPI(int8** ptr)
如果我想将结构体的指针传递给这个函数,这是我的代码:
typedef myStruct {
int a;
};
myStruct *ptr = NULL;
memset(ptr, 0, sizeof(myStruct));
myAPI((int8**)&ptr);
我的问题是,如果我现在不使用 ptr
而是使用以下内容会怎样?
myStruct myStruct_info;
memset(&myStruct_info, 0, sizeof(myStruct));
我也会做myAPI((int8**)&myStruct_info)
吗?
最佳答案
Would I also be doing myAPI((int8**)&myStruct_info)?
简短的回答是不,你不能。
&myStruct_info
是 myStruct_info
变量的地址。
myAPI 函数的参数需要指向变量的指针的地址。
如果你说int8 ** a = (int8**)&myStruct_info;
那么:
a - holds the address of myStruct_info
*a - the value of myStruct_info
和
**a - means that you take the value stored in myStruct_info and use it as a pointer - REALLY BAD -
关于c - 在 C 中将双指针作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50339581/