c - 解引用指针构造的地址

标签 c pointers syntax dereference addressof

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/

相关文章:

c++ - 如何初始化作为构造函数中的类成员的共享指针

c - for循环无故停止

haskell - Haskell 中的点运算符 : need more explanation

c - 在下面的代码中: get_row_of_machine receiving mon_param as a parameter thread-safe?

c++ - 在 C++ 中访问预定义 float 组时出现问题

c - 关于 strcpy 中的安全漏洞

python - **(双星/星号)和 *(星号/星号)对参数有何作用?

syntax - === 运算符在 Kotlin 中的作用是什么?

OS X 中使用 openmp 的 Python 扩展

C++。将二维指针数组传递到函数时遇到问题