You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/cgo: cannot call functions with variable-argument lists. #975
A package such as the following will not compile with cgo.
(printf is a contrived example, but this would be useful for bridging objective c
through id objc_msgSend(id self, SEL op, ...);)
--- (file foo.go)
package foo
// #include <stdio.h>
import "C"
func PrintStuff() {
C.printf(C.CString("Hello"))
}
---
$ cgo foo.go
What is the expected output?
Program compiles and is able to call function with variable-argument list.
What do you see instead?
unexpected type: ...
What is your $GOOS? $GOARCH?
darwin amd64
Which revision are you using? (hg identify)
43fd9bb529f0+ tip
Reacted by darasion, 陈杨文, Cedric Zhuang, Maple and Linden
... That is, if you want to call the C function printf() from Go code, you write C.printf(). Since variable argument methods like printf aren't supported yet (issue 975), we will wrap it in the C method "myprint":...
The documentation of cgo should be more explicit for the issue, but now it not even mention this.
n order to implement this, we need to be able to rewrite
C.printf(C.CString("%d %s"), 1, C.CString("2"))
into a call to a generated Go function
GoWrapper(C.CString("%d %s"), 1, C.CString("2"))
which means that we need to generate
func GoWrapper(p1 *C.char, p2 int, p3 *C.char)
and similarly for a C wrapper function.
That is all fine, but in order to write these functions we need to know the types of the Go arguments. Normally we can simply use the types of the C function parameters, which we can get from the C debug info. But of course for a C variadic function we have no type information for the variadic arguments. That means that we need to use the types of the Go arguments. But currently cgo does not know those types.
Activity
rsc commentedon Jul 29, 2010
Comment 1:
Labels changed: added priority-low, removed priority-medium.
Owner changed to r...@golang.org.
Status changed to LongTerm.
gopherbot commentedon Jul 30, 2010
Comment 2 by akidan:
rsc commentedon Dec 9, 2011
Comment 3:
Labels changed: added priority-someday.
rsc commentedon Dec 4, 2013
Comment 5:
Labels changed: added repo-main.
rsc commentedon Mar 3, 2014
Comment 6:
Labels changed: added release-none.
LionNatsu commentedon Jan 24, 2018
I think this should be documented as it is a long-term issue.
While wiki says:
The documentation of cgo should be more explicit for the issue, but now it not even mention this.
2 remaining items
cgo: update documentation on calling C variadic functions
cgo: update documentation on calling C variadic functions
InsertWithTag() is a wrapper around gtk_text_buffer_insert_with_tags(…
bradfitz commentedon Feb 2, 2021
This would help with @progrium's MacDriver:
https://dev.to/progrium/use-mac-apis-and-build-mac-apps-with-go-ap6
/cc @ianlancetaylor
ianlancetaylor commentedon Feb 7, 2021
n order to implement this, we need to be able to rewrite
into a call to a generated Go function
which means that we need to generate
and similarly for a C wrapper function.
That is all fine, but in order to write these functions we need to know the types of the Go arguments. Normally we can simply use the types of the C function parameters, which we can get from the C debug info. But of course for a C variadic function we have no type information for the variadic arguments. That means that we need to use the types of the Go arguments. But currently cgo does not know those types.
So I think this has to wait for #16623.