Skip to content
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: use void keyword in generated headers on extern'd function declarations with no params #68411

Open
sixcorners opened this issue Jul 13, 2024 · 4 comments · May be fixed by #70981
Open
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Milestone

Comments

@sixcorners
Copy link

Proposal Details

I propose that the generated header files from --buildmode=c-shared have void in the parenthesis when the extern'd function takes no parameters.
In C, function declarations with an empty list of parameters means that the parameters are unknown. The way to declare a function that takes no parameters is to put the void keyword in the parenthesis. If you omit the void keyword then callers are allowed to specify any number of parameters to the function, although compilers can issue warnings when this happens.

In my case I'm using jextract to generate java bindings for a header file generated by a go project. It's is kind of a new tool. When it sees the empty parameter list it treats the function as variadic which looks slightly different on the java side. This doesn't really matter much though. I'm just including this here for context.

I'm unsure what backwards compatibility concerns something like this would have. In the case of jextract it changes everything about the function call on the java side. I don't know if there are other tools that would be greatly affected by this change.

@gopherbot gopherbot added this to the Proposal milestone Jul 13, 2024
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Jul 13, 2024
@ianlancetaylor ianlancetaylor changed the title proposal: cmd/cgo: void keyword in generated headers on extern'd function declarations with no params? cmd/cgo: use void keyword in generated headers on extern'd function declarations with no params Jul 13, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2024
@ianlancetaylor
Copy link
Member

I don't think this has to be a proposal, I think we can just make this change. Want to send a patch? Thanks.

@seankhliao seankhliao modified the milestones: Proposal, Backlog Jul 13, 2024
@cherrymui cherrymui added NeedsFix The path to resolution is known, but the work has not been done. help wanted labels Jul 16, 2024
@nagalakvenkat
Copy link

Is this still open and needs a patch?

@ianlancetaylor
Copy link
Member

Yes. Any patch should appear in this issue, and I don't see one.

@mauri870 mauri870 self-assigned this Dec 24, 2024
@mauri870 mauri870 removed help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Dec 24, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/638635 mentions this issue: cmd/cgo: explicitly use void for functions with no parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
Development

Successfully merging a pull request may close this issue.

7 participants