I can pass a C function pointer to a C function, but passing it to a go function gives invalid operation.
I have 100 go functions wrapping C functions and most share the same setup and arguments so I wanted to implement one go function that can take a C function pointer to make this easier to maintain.
<code>package main
/*
#include <stdio.h>
typedef void (*func_t)(int);
void this_works(int a, func_t f){
f(a);
}
void tst(int a) {
printf("YAYn");
}
*/
import "C"
func this_does_not_work( fp C.func_t ) {
fp(2) // invalid operation: cannot call non-function fp (variable of type _Ctype_func_t)
}
func main() {
C.this_works(1, C.func_t(C.tst))
this_does_not_work( C.func_t(C.tst) )
}
</code>
<code>package main
/*
#include <stdio.h>
typedef void (*func_t)(int);
void this_works(int a, func_t f){
f(a);
}
void tst(int a) {
printf("YAYn");
}
*/
import "C"
func this_does_not_work( fp C.func_t ) {
fp(2) // invalid operation: cannot call non-function fp (variable of type _Ctype_func_t)
}
func main() {
C.this_works(1, C.func_t(C.tst))
this_does_not_work( C.func_t(C.tst) )
}
</code>
package main
/*
#include <stdio.h>
typedef void (*func_t)(int);
void this_works(int a, func_t f){
f(a);
}
void tst(int a) {
printf("YAYn");
}
*/
import "C"
func this_does_not_work( fp C.func_t ) {
fp(2) // invalid operation: cannot call non-function fp (variable of type _Ctype_func_t)
}
func main() {
C.this_works(1, C.func_t(C.tst))
this_does_not_work( C.func_t(C.tst) )
}