I'm new to Go and I wish to translate some C/C++ code I have to Go but I haven't been able to. The problem resides in 2 places: how can I initialize a struct I've defined and how to do a "memcopy"
The code I'm talking about is this: http://play.golang.org/p/e8N255qEAk line 69 and 74.
The C/C++ code I wanted to "translate" to Go is this:
typedef char xchr;
typedef int xint;
typedef double xdob;
typedef float xflt;
typedef struct
{
xint p;
xdob lat_lon_ele[3];
xflt psi_the_phi[3];
xflt gear_flap_vect[3];
}VEH1;
avio.p = 0;
avio.lat_lon_ele[0] = 47.460058;
avio.lat_lon_ele[1] = -122.32104;
avio.lat_lon_ele[2] = 8000.000;
avio.psi_the_phi[0] = 110.5;
avio.psi_the_phi[1] = 0.0;
avio.psi_the_phi[2] = 0.0;
avio.gear_flap_vect[0] = 1.0;
avio.gear_flap_vect[1] = 0.0;
avio.gear_flap_vect[2] = 0.0;
VEH1* av = &avio;
xchr data_send[6];
data_send[0]='V';
data_send[1]='E';
data_send[2]='H';
data_send[3]='1';
data_send[4]=0;
memcpy(&data_send[5],av,sizeof(VEH1)); // load in the data
The Go code looks like this:
type xchr int8
type xint int
type xdob float64
type xflt float32
type VEH1 struct {
p xint
lat_lon_ele [3]xdob
psi_the_phi [3]xflt
gear_flap_vect [3]xflt
}
type VEHA struct {
num_p xint
lat_lon_ele [10][3]xdob
psi_the_phi [10][3]xflt
gear_flap_vect [10][3]xflt
lat_view, lon_view, ele_view xdob
psi_view, the_view, phi_view xflt
}
var avio VEH1
avio = &VEH1{0, {47.460058, -122.32104, 8000.000}, {110.5, 0.0, 0.0}, {1.0, 0.0, 0.0}}
data_send := [6]xchr{'V', 'E', 'H', '1', 0, 0}
copy(data_send[5:5], avio);
Thank you!