I have a C function which will return an array of structure to go function. How can I receive the array of structure and interpret or cast to go structure?
Here is the code snippet
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;
}
I need to get the pStudent array in my go code
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() //?????
}
Can some one help me with code snippet?