typedef struct _name name;
struct _name { char name[256]; };
// ...
name Name;
char *buf = (char*)malloc( 256*sizeof(char) );
// ...
// if I do not want to write strcpy (Name.name,buf);
// and write: list_name_insert (&List,0,&Name);
// if just write:
list_name_insert (&List,0 /* index */,(name*)buf /* pointer to elem */);
// Will it be correct?
// ...
在标准 C 函数 list_name_insert 中逐字段复制执行。
也就是说,是不是一样的srtuct { char[];
和 ANSI C 中的 char*
?
最佳答案
将这两个问题合二为一的答案是否定的。
只有一个成员的 struct
有一个 struct
类型;它的类型与其单个成员不同。
此外,数组和指针不是一回事。数组可以衰减为指针,如
char buf[256];
char *p = buf;
反之则不然。
关于c - C中的struct由1个字段组成,是同一类型的字段吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14609763/