Skip to content

Commit

Permalink
cmd/cgo: use full prototype for main in C code
Browse files Browse the repository at this point in the history
Avoids pedantic errors from modern C compilers.

Fixes #70769

Change-Id: Ibe0d9960e998eb0346b97d7bd69eb7de0d0e6c60
Reviewed-on: https://go-review.googlesource.com/c/go/+/635095
Reviewed-by: Robert Griesemer <[email protected]>
Reviewed-by: Mauri de Souza Meneguzzo <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Commit-Queue: Ian Lance Taylor <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Dec 11, 2024
1 parent 0ca521f commit fafd447
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cmd/cgo/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ Instead, the build process generates an object file using dynamic
linkage to the desired libraries. The main function is provided by
_cgo_main.c:
int main() { return 0; }
int main(int argc, char **argv) { return 0; }
void crosscall2(void(*fn)(void*), void *a, int c, uintptr_t ctxt) { }
uintptr_t _cgo_wait_runtime_init_done(void) { return 0; }
void _cgo_release_context(uintptr_t ctxt) { }
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cgo/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *Package) writeDefs() {

// Write C main file for using gcc to resolve imports.
fmt.Fprintf(fm, "#include <stddef.h>\n") // For size_t below.
fmt.Fprintf(fm, "int main() { return 0; }\n")
fmt.Fprintf(fm, "int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) { return 0; }\n")
if *importRuntimeCgo {
fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*) __attribute__((unused)), void *a __attribute__((unused)), int c __attribute__((unused)), size_t ctxt __attribute__((unused))) { }\n")
fmt.Fprintf(fm, "size_t _cgo_wait_runtime_init_done(void) { return 0; }\n")
Expand Down

0 comments on commit fafd447

Please sign in to comment.