在unqlite c库中,我找到了以下代码:
pObj = jx9VmReserveMemObj(&(*pVm),&nIdx);
其中pVm是:
typedef struct jx9_vm jx9_vm; jx9_vm *pVm
jx9_value * jx9VmReserveMemObj(jx9_vm *,sxu32 *);
什么构造&(* pVm)用于调用而不仅仅是pVm? &(* pVm)是否相当于pVm?
解决方法
引用C11,章节§6.5.3.2,地址和间接操作符
[…] If the operand is the result of a unary
*
operator,
neither that operator nor the&
operator is evaluated and the result is as if both were
omitted,except that the constraints on the operators still apply and the result is not an lvalue. […]
所以,是的,它们是等价的.
但是,可以使用此构造来检查针对指针类型的参数类型.从一元*运算符的属性,
The operand of the unary
*
operator shall have pointer type.
所以,构造&(* pVm)
>如果pvm是指针或数组名称,那就没问题.
如果pvm是非指针类型变量,>将生成编译器错误.
有关代码示例,请参见the other answer by Alter Mann.
另外一个区别(通常)是,可以分配pVm(可以用作赋值运算符的LHS),但是&(* pVm)不能.