我尝试编译以下代码,但编译器不会执行此操作,因为“ * 对于结构来说是非法的”,这是真的吗?
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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)