-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: document that static functions work, static variables do not #9673
Comments
It depends on how cgo is implemented, you shouldn't rely on being able to |
It does seem inconsistent, though, and I think it should be fixed or documented. |
Do you want to fix it or document it? I think the correct fix is to disallow calling static functions defined in Given that we have never documented about this, the safest way is to What do you prefer? |
I agree that people call static functions today, and that it seems undesirable to break that. We even test it in misc/cgo/test, and I seem to recall fixing cgo so that those tests worked with gccgo. I guess I don't see why static variables can't work in principle. We could generate static getters and setters and rewrite references in the Go code. Unless that seems infeasible perhaps we should leave this open in case somebody wants to fix it. |
Seems easy to fix because we already use a pointer to access C variables, The only problem is that we must make sure to only emit the pointer definition I don't want to go the SWIG way, because Go is more capable than common |
I think cgo can detect a static variable by looking at the ELF symbol binding in the symbol table of cgo.o (or equivalent for the other formats). |
As I understand it, static functions have always worked, and static variables have never worked. That seems perfectly fine. Let's document it and move on. |
CL https://golang.org/cl/11221 mentions this issue. |
Discussion from #go-nuts on irc:
Sample code:
The text was updated successfully, but these errors were encountered: