如何在free_x函數內部初始化x?我必須這樣做才能適應API方法。我可以非常容易地通過將null賦值給它來初始化x,但是我必須在free_x函數內部執行它。將null指定給指針的地址
typedef struct
{
int field1;
void *field2;
}my_struct;
static my_struct var;
int main(void)
{
void *x;
alloc_x(&x);
free_x(x); // x = NULL works but not allowed
return 0;
}
void alloc_x(void **param)
{
*param = (my_struct *)&var;
}
void free_x(void *param)
{
// how can I free param here?
}
'* param = NULL;'.......?; – LPs
* param = NULL應該可以工作 –
指針的_address_?或者指針_point_的地址? – byxor