【发布时间】:2020-09-14 12:00:00
【问题描述】:
我有一个 C 结构
struct Test {
int a;
}
typedef struct Test Test;
在 C 中我创建了一个指针,
Test* myTestPointer = new Test();
我在 Swift 中获得了结构指针 myTestPointer,并且我检查了该指针确实在 Swift 和 C 中都指向正确的地址。
但我很难理解为什么以下两段代码不等同于 C 代码中 a 的值衡量?
let x = myTestPointer
x!.pointee.a = 123 // correctly changes the memory, as reflected back in C code
var x = myTestPointer!.pointee
x.a = 123 // does not reflect change back in C code
【问题讨论】:
-
C 和 C++ 是不同的语言。