在 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)
不能。
关于c - 解引用指针构造的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38915128/