diff options
author | Ian Lance Taylor <iant@golang.org> | 2016-01-12 07:03:28 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2016-01-12 17:31:01 +0000 |
commit | 505fa7b42338f0aba7e4235acbc8274a20f3c1f0 (patch) | |
tree | c9ade4e028467442fc28a45c99a066947a458aab | |
parent | eca3618fd3977512fb9c6aded3e373b7729b952c (diff) | |
download | go-505fa7b42338f0aba7e4235acbc8274a20f3c1f0.tar.gz go-505fa7b42338f0aba7e4235acbc8274a20f3c1f0.zip |
cmd/cgo: document C.sizeof_T and zero-sized field restriction
Update #9401.
Update #11925.
Update #13919.
Change-Id: I52c679353693e8165b2972d4d3974ee8bb1207ef
Reviewed-on: https://go-review.googlesource.com/18542
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
-rw-r--r-- | src/cmd/cgo/doc.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index 8ec4301112..bd38a5c153 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -125,11 +125,19 @@ The C types __int128_t and __uint128_t are represented by [16]byte. To access a struct, union, or enum type directly, prefix it with struct_, union_, or enum_, as in C.struct_stat. +The size of any C type T is available as C.sizeof_T, as in +C.sizeof_struct_stat. + As Go doesn't have support for C's union type in the general case, C's union types are represented as a Go byte array with the same length. Go structs cannot embed fields with C types. +Go code can not refer to zero-sized fields that occur at the end of +non-empty C structs. To get the address of such a field (which is the +only operation you can do with a zero-sized field) you must take the +address of the struct and add the size of the struct. + Cgo translates C types into equivalent unexported Go types. Because the translations are unexported, a Go package should not expose C types in its exported API: a C type used in one Go package |