简体   繁体   中英

Array of structs - Array has incomplete element type (in C)

This seems like an easy problem to fix, but i'm doing something wrong. I've been through all the similar threads and didn't find anything that solved my problem, so any help would be appreciated!

Basically: C program, and i'm trying to create an array of bufferevents.

#include <event2/listener.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>

extern struct bufferevent bev[8];

//Then, my accept functions -- well, one of them...
static void accept1(struct evconnlistener *listener,
    evutil_socket_t fd, struct sockaddr *address, int socklen,
    void *ctx) {
    /* A new connection was received on this port */
    struct event_base *base = evconnlistener_get_base(listener);
    bev[0] = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE);

    /* Callback for when (*bufevent, data READ, data WRITTEN, event OCCURRED, *void) */
    bufferevent_setcb(bev[0], read1, NULL, echo_event_cb, NULL);
} 

When i attempt to compile (WITH -levent, i might add) i get this error:

src/mix/mix1.c:57:34: error: array type has incomplete element type

Any ideas? :(

Note: I am defining the bufferevents outside of main to make them accessible everywhere in my code without passing them. I have other #define's in the area, so i'm sure it's something to do with the way i'm building them??

struct bufferevent is only declared as an incomplete type in libevent's public headers; its contents are hidden to users of the public API. All the libevent functions that operate on bufferevents take a pointer to a bufferevent, so what you want here is

struct bufferevent *bev[8];

Note further that you do NOT want to put extern on that declaration or you'll get an undefined symbol error at link time. If it is only ever referred to in that file , you should use static instead. Otherwise there should be a declaration with extern in one of your application's header files in addition to the extern -less declaration in the file you showed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM