packed struct 字段地址 #13
jiacai2050
started this conversation in
观点交流
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
上面依次输出
从第三行可以看到,b、c 输出的地址都是一样的,那 zig 内部是怎么区分 b、c 的呢?从第一行打印的类型来看,有一种推测:
b、c 内部共享一长度为 20 的数组,然后通过不同的 align 来确认值的起点,比如
(:0:20)
表示从第 0 个地址开始(:80:20)
表示从第 80 个地址开始通过 lldb 可以看到 a、b、c 字段的真正地址:
从上面也能看出, zig 里面对于 packed struct 的字段取地址,拿到的可能不是真实的地址
Beta Was this translation helpful? Give feedback.
All reactions