golang/go

cmd/cgo: cgo "//export" usage missing crucial info

Open

#56,853 opened on Nov 19, 2022

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Go (19,008 forks)batch import
DocumentationNeedsFixhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

What is the URL of the page with the issue?

https://pkg.go.dev/cmd/cgo

About "//export".

While the example code itself shows correct usage, the paragraph surrounding it doesn't say two things you should NOT do:

  1. Other "functional" comments in cgo allows beginning white spaces. Thus, for readability, one does (with a space between "//" and "#")
// #cgo pkg-config: ...

"//export" does not allow a space between. It is also extremely difficult to find out when the space should be deleted for this to work as intended. (A suitable warning if "// export ..." is used?)

  1. The other less important thing is trailing garbage/comments. Though a suitable error is emitted, it would be nice to be able to do have trailing comments like this:
//export MyRoutine // used by MyOtherProject
  1. It is also not clear whether the "//export MyRoutine" and the next line "func MyCoolRoutine ..." name must match. One might want to name routines by Go convention in Go code, but export as a different name following C code's naming conventions, for example?

What is your user agent?

Screenshot

What did you do?

What did you expect to see?

What did you see instead?

Contributor guide