[英]too few values in struct initializer when initialize C struct in golang
I have tried the following program, but it told me "too few values in struct initializer" when compiling it. 我已经尝试了以下程序,但它在编译时告诉我“struct initializer中的值太少”。
package main
/*
#include <stdlib.h>
struct Person {
char *name;
int age;
int height;
int weight;
};
*/
import "C"
import "fmt"
type p C.struct_Person
func main() {
person := p{C.CString("Giorgis"), 30, 6, 175}
fmt.Println(person)
fmt.Println(C.GoString(person.name))
fmt.Println(person.age)
fmt.Println(person.height)
fmt.Println(person.weight)
}
How can I fix this wired problem? 我该如何解决这个有线问题? Additionally, when I changed type "char*" to "char", and the initializer.
另外,当我将类型“char *”更改为“char”和初始化程序时。 It works well.
它运作良好。
struct Person {
char name;
int age;
int height;
int weight;
};
Also, when I use 另外,当我使用时
struct Person {
char *name;
};
it works well too. 它也运作良好。
Anyway, how can I fix it? 无论如何,我该如何解决? Thanks.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.