关于取消引用不完整类型的指针 [英] about dereferencing pointer to incomplete type

查看:117
本文介绍了关于取消引用不完整类型的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作了几个小时,但是我解决不了,
所以请告诉我为什么?

在lxhttpd_netbase.h

i have worked some hours, but i can''t solved it,
so please tell me why?

in the lxhttpd_netbase.h

/**
  handle read/write callback.
*/
typedef void ( *read_write_cb )( int fd, void *arg );
struct fd_set;
struct timeval;
/**
  a tcp server.
*/
struct tcp_server
{
        // socket: file descriptor
        int fd;
        // fd set
        struct fd_set *fd_readset;
        struct fd_set *fd_writeset;
        struct fd_set *fd_set;
        // max connection
        int max_con;
        // read/write callback
        read_write_cb read_cb;
        read_write_cb write_cb;
        // argument for read/write callback
        void *arg;
};




在lxhttpd_netbase.c




in the lxhttpd_netbase.c

#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h>
#include <string.h>
#include "lxhttpd_netbase.h"
#include <unistd.h>

/*
  set fd set
*/
static void _server_set_fd( struct tcp_server *server )
{
        memcpy( server->fd_readset->fd_array, server->fd_set->fd_array, sizeof( server->fd_set->fd_array[0] ) * server->fd_set->fd_count );
        server->fd_readset->fd_count = server->fd_set->fd_count;
        memcpy( server->fd_writeset->fd_array, server->fd_set->fd_array, sizeof( server->fd_set->fd_array[0] ) * server->fd_set->fd_count );
        server->fd_writeset->fd_count = server->fd_set->fd_count;
        FD_SET( server->fd, server->fd_readset );
        //FD_SET( server->fd, server->fd_writeset );
}





当我通过 gcc -o lxhttpd_netbase -g lxhttpd_netbase.c
进行编译时 会出来的:





and when i complier it by gcc -o lxhttpd_netbase -g lxhttpd_netbase.c
it will come out :

lxhttpd_netbase.c: In function_server_set_fd’:
lxhttpd_netbase.c:46: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:46: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:46: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:46: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:47: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:47: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:48: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:48: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:48: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:48: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:49: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:49: error: dereferencing pointer to incomplete type
lxhttpd_netbase.c:50: error: dereferencing pointer to incomplete type




请帮助我,非常感谢.

我已经将文件包含在lxhttpd_netbase.h中:




please help me, thank you very much.

i have included the files in the lxhttpd_netbase.h :

#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>



但它仍然不起作用.谢谢



but it still don''t work. thank you

推荐答案

可能是因为缺少对fd_set的明确定义-您的lxhttpd_netbase.h文件将其定义为:
Probably, it is the lack of a firm definition of fd_set - your lxhttpd_netbase.h file defines it as:
struct fd_set;

尝试包含包含完整定义的文件,该错误应消失.

目前,您尝试访问tcp_server结构的server->fd_readset->fd_array等元素,但编译器对此一无所知!

Try to include the file containing the full definition, and the error should disappear.

At the moment, you try to access the server->fd_readset->fd_array etc. elements of your tcp_server structure, but the compiler doesn''t know anything about them!


如果我必须在此使用fd_set方式,我必须包含"Winsock2.h",
在Linux中,我们不能使用fd_cout和fd_array.因为fd_set是:
if i must use fd_set in this way , i must include "Winsock2.h",
in linux, we can''t use fd_cout and fd_array. because fd_set is:
#undef __NFDBITS
#define __NFDBITS       (8 * sizeof(unsigned long))
 
#undef __FD_SETSIZE
#define __FD_SETSIZE    1024
 
#undef __FDSET_LONGS
#define __FDSET_LONGS   (__FD_SETSIZE/__NFDBITS )
typedef struct {
          unsigned long fds_bits [__FDSET_LONGS];
  } fd_set;


这篇关于关于取消引用不完整类型的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆