expected specifier-qualifier-list before

有问题的代码如下:

这段代码编译后出现如下问题:error: expected specifier-qualifier-list before ‘tts_server_status_t’

问题是在定义类型之前使用了类型。

typedef struct server_group{
    char groupName[128];
    unsigned short gruopStatus;
    server_status_t *serverList;
    server_group_t *next;
}server_group_t;

typedef struct server_status{
    char serverIp[128];
    unsigned int port;
    unsigned short status;
    server_group_t *group;
    server_status_t *next;
}server_status_t;

有两种解决办法。

第一种:在使用前用typedef定义类型:

typedef struct server_group server_group_t;
typedef struct server_status server_status_t;
struct server_group{
	char groupName[128];
	unsigned short gruopStatus;
	server_status_t *serverList;
	server_group_t *next;
};

struct server_status{
	char serverIp[128];
	unsigned int port;
	unsigned short status;
	server_group_t *group;
	server_status_t *next;
};

第二种:用结构体类型之前加struct关键字

struct server_group{
	char groupName[128];
	unsigned short gruopStatus;
	struct server_status_t *serverList;
	struct server_group_t *next;
};

struct server_status{
	char serverIp[128];
	unsigned int port;
	unsigned short status;
	struct server_group_t *group;
	struct server_status_t *next;
};

这样就可以顺利通过编译了。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>