如何解决如何在Go中映射具有指针的结构,该结构来自Windows系统调用?
假设我在C中具有以下结构:
struct Foo {
int *number;
};
Foo
是从Windows系统调用返回的。 number
字段由Windows填充,我必须取消引用并在Go中使用此值。
我可以想象三种方式:
1。)存储uintptr
:
type Foo struct {
Number uintptr
}
// Then use Number as:
foo := SomeFunc()
val := (*int32)(unsafe.Pointer(foo.Number))
2。)存储unsafe.Pointer
:
type Foo struct {
Number unsafe.Pointer
}
// Then use Number as:
foo := SomeFunc()
val := (*int32)(foo.Number)
3。)存储*int32
本身:
type Foo struct {
Number *int32
}
// Then use Number as:
foo := SomeFunc()
val := *foo.Number
哪个是正确的?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。