我试图编译以下代码,但编译器不会这样做,因为“* 对于结构是非法的”是真的吗?
struct String {
int length;
int capacity;
unsigned check;
char ptr[0];
} String;
void main(){
char *s;
String *new_string = malloc(sizeof(String) + 10 + 1);
}
最佳答案
要么使用 typedef:
typedef struct String {
int length;
int capacity;
unsigned check;
char ptr[0];
} String; /* now String is a type */
或者明确地说struct String
:
void main(){
char *s;
struct String *new_string = malloc(sizeof(struct String) + 10 + 1);
}
关于c - * 对于结构是非法的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1622323/