Skip to content

Commit

Permalink
cmd/cgo: document workaround for C struct_stat function
Browse files Browse the repository at this point in the history
For #68682

Change-Id: I13b61f915925a9ee510e0a42e95da7a83678b3b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/602215
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Jul 31, 2024
1 parent 2c1bbe7 commit fa861f8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/cmd/cgo/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ type in Go are instead represented by a uintptr. See the Special
cases section below.
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.
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. These
special prefixes means that there is no way to directly reference a C
identifier that starts with "struct_", "union_", "enum_", or
"sizeof_", such as a function named "struct_function".
A workaround is to use a "#define" in the preamble, as in
"#define c_struct_function struct_function" and then in the
Go code refer to "C.c_struct_function".
A C function may be declared in the Go file with a parameter type of
the special name _GoString_. This function may be called with an
Expand Down

0 comments on commit fa861f8

Please sign in to comment.