当前位置: 技术问答>linux和unix
dereferencing pointer to incomplete type····
来源: 互联网 发布时间:2016-09-26
本文导语: 代码: struct event *ev = arg; struct sockaddr addr; int s; socklen_t len = sizeof(addr); struct event *rev = (struct event *)malloc(sizeof(*rev)); ///////////////// ...
代码:
struct event *ev = arg;
struct sockaddr addr;
int s;
socklen_t len = sizeof(addr);
struct event *rev = (struct event *)malloc(sizeof(*rev)); ///////////////// 137行
if((s = accept(server_socket, &addr, &len)) == -1)
{
fprintf(stderr, "Sock Accept Failed!n");
exit(0);
}
········
········
int
main () //int argc, char **argv
{
struct event *ev;
int server_socket;
struct sockaddr_in addr;
server_socket = socket(AF_INET, SOCK_STREAM, 0);
if (server_socket == -1)
{
perror("socket errorn");
exit(-1);
}
bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(PORT);
addr.sin_addr.s_addr =htonl(INADDR_ANY); //INADDR_ANY;IPADDR
if (bind(server_socket, (struct sockaddr*)&addr, sizeof(addr)) == -1)
{
perror("bind errorn");
exit(-1);
}
if (listen(server_socket, 5) == -1)
{
perror("listen errorn");
exit(-1);
}
event_init();
event_set(&ev, server_socket,EV_READ, sock_accept, &ev); ///////////////// 147行
event_add(&ev, NULL);
event_dispatch();
return (0);
}
错误提示:137:dereferencing pointer to incomplete type
147: error: ‘EV_READ’ undeclared (first use in this function)
147: error: (Each undeclared identifier is reported only once
147: error: for each function it appears in.)
对于147行这种修改属性 EV_READ|EV_WRITE 我写成 EV_READ 提示如上····为什不对?能讲下原因 吗?
请问各位,这两个问题我应该怎么改?
谢谢!!!
struct event *ev = arg;
struct sockaddr addr;
int s;
socklen_t len = sizeof(addr);
struct event *rev = (struct event *)malloc(sizeof(*rev)); ///////////////// 137行
if((s = accept(server_socket, &addr, &len)) == -1)
{
fprintf(stderr, "Sock Accept Failed!n");
exit(0);
}
········
········
int
main () //int argc, char **argv
{
struct event *ev;
int server_socket;
struct sockaddr_in addr;
server_socket = socket(AF_INET, SOCK_STREAM, 0);
if (server_socket == -1)
{
perror("socket errorn");
exit(-1);
}
bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(PORT);
addr.sin_addr.s_addr =htonl(INADDR_ANY); //INADDR_ANY;IPADDR
if (bind(server_socket, (struct sockaddr*)&addr, sizeof(addr)) == -1)
{
perror("bind errorn");
exit(-1);
}
if (listen(server_socket, 5) == -1)
{
perror("listen errorn");
exit(-1);
}
event_init();
event_set(&ev, server_socket,EV_READ, sock_accept, &ev); ///////////////// 147行
event_add(&ev, NULL);
event_dispatch();
return (0);
}
错误提示:137:dereferencing pointer to incomplete type
147: error: ‘EV_READ’ undeclared (first use in this function)
147: error: (Each undeclared identifier is reported only once
147: error: for each function it appears in.)
对于147行这种修改属性 EV_READ|EV_WRITE 我写成 EV_READ 提示如上····为什不对?能讲下原因 吗?
请问各位,这两个问题我应该怎么改?
谢谢!!!
|
struct event *rev = (struct event *)malloc(sizeof(*rev));
应该是sizeof(struct event)
应该是sizeof(struct event)
|
struct event 结构的定义有定义么? 有定义的话,包含它相应头文件罗。
如果是同一文件后面部分定义的,那么在引用前加个前置声明。
如果是同一文件后面部分定义的,那么在引用前加个前置声明。