我有一个 C 函数,它将返回一个结构数组来运行函数。如何接收结构数组并解释或转换为结构?
这是代码片段
typedef struct student{
nameStruct name;
addressStruct address;
} studentStruct;
typedef struct name{
char firstName[20];
char lastName[20];
} nameStruct;
typedef struct address{
char location[40];
int pin;
}addressStruct;
student* getAllStudents(){
//Allocate memory for N number of students
student *pStudent= (struct student*)(N* sizeof(struct student));
//populate the array
return pStudent;
}
我需要在我的 go 代码中获取 pStudent 数组
package main
/*
#cgo CFLAGS: -I.
#cgo LDFLAGS: -L. -lkeyboard
#include "keyboard.h"
*/
import "C"
import (
"fmt"
)
type student struct {
name string
ID int
}
func main() {
s := student{} //Need to know how to decide the length of the struct array
s = C.getAllStudents() //?????
}
有人可以帮我处理代码片段吗?