【发布时间】:2016-03-14 18:28:20
【问题描述】:
为什么这不起作用:
#define PORT_ID_MAX_CHAR 6
typedef struct {
int phys;
char name[PORT_ID_MAX_CHAR];
}tPortMap;
struct tPortMap c_portMap[] = { 0, "test" }, { 1,"test" };
GCC 对我咆哮说myfile.c:8:46: error: expected identifier or ‘(’ before ‘{’ token
struct tPortMap c_portMap[] = { 0, "test" }, { 1,"test" };,我不知道为什么......我很困惑......
EDIT1
使用额外的大括号我得到了错误:
struct tPortMap c_portMap[] = {{ 0, "test" }, { 1,"test" }};
myfile.c:8:17: error: array type has incomplete element type
struct tPortMap c_portMap[] = {{ 0, "test" }, { 1,"test" }};
【问题讨论】:
-
struct tPortMap c_portMap[] = {{ 0, "test" }, { 1,"test" }};解决问题了吗? -
我差点错过了
6... -
请参阅上面的EDIT1
-
不是
struct tPortMap,只是tPortMap -
是的,我愿意,它们都在同一个文件中。
标签: c struct initialization