-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/cgo: emit forward-declarations for cgo-exported Go functions #19837
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
Comments
(CC: @ianlancetaylor @thanm) |
I've also encountered this. It seems unnecessary. |
Ping Ian and Tham. Thoughts? |
Seems fine if someone wants to do it. |
Worth fixing I agree, but I don't think I have time to work on this in the near term |
Another reason why it really should be cgo that handles the declaration is that for now you have to manually adapt to e.g. the way these functions are exported on Windows and do things like: #if _WIN32
void __declspec(dllexport) go_print_hello();
#else
void go_print_hello();
#endif |
I'm trying to pass a Go function as a C function pointer.
I expect to be able to do that by exporting the Go function to C, then passing the C name of the Go function:
Unfortunately, that results in a cgo error:
As a workaround, I can add an explicit forward-declaration of the Go function to the C preamble:
Given that cgo (presumably) already knows the C declarations for the functions it is exporting, I would prefer that it emit those forward-declarations itself. Since all C types should be defined by the end of the user-defined preamble, it seems like cgo could emit the forward declarations immediately following the preamble.
(If user code needs to refer to the Go functions within the preamble itself, requiring an explicit forward-declaration seems reasonable.)
The text was updated successfully, but these errors were encountered: