我必须从Go调用C函数。 C函数采用2d整数数组和其他一些参数。我努力通过C函数传递Go 2d整数数组。
我已经将go数组创建为C.int类型,并传递给了c函数。它显示:
cannot use G (type [10][10]_Ctype_int) as type *[10]_Ctype_int in argument to _Cfunc_dijkstra
这里的dijkstra函数是在merge_sort.c文件中实现的
package main
// #include "merge_sort.c"
import "C"
func main(){
var G = [10][10] C.int {
{0, 3, 4, 0, 0, 0, 0, 0, 0, 0},
{3, 0, 0, 4, 5, 0, 0, 0, 0, 0},
{4, 0, 0, 4, 0, 6, 0, 0, 0, 0},
{0, 4, 4, 0, 5, 3, 7, 0, 0, 0},
{0, 5, 0, 5, 0, 0, 4, 0, 6, 0},
{0, 0, 6, 3, 0, 0, 3, 3, 0, 0},
{0, 0, 0, 7, 4, 3, 0, 2, 1, 3},
{0, 0, 0, 0, 0, 3, 2, 0, 0, 3},
{0, 0, 0, 0, 6, 0, 1, 0, 0, 3},
{0, 0, 0, 0, 0, 0, 3, 3, 3, 0},
}
var n C.int= 10
var u C.int= 0
C.dijkstra(G, n ,u)
}
c函数如下所示
void dijkstra(int G[10][10],int n,int startnode);