简体   繁体   中英

Avoid warning when two structs include each other

I'm trying to implement a thread pooling system in my application. I would love that each thread has a pointer to the thread pooling structure I'm using. So, basically I've two structure similar to what follows:

typedef struct thread_pool {
    /* some fields here */
    single_thread **tds;
} thread_pool_t;

typedef struct single_thread {
    /* some fields here */
    thread_pool_t *tp;
} single_thread_t;

Independently of the order of declaration, the compiler will give an error. I solved declaring the second structure before the first one, but declaring it empty. Now I don't get any errors, but I always get the following warning:

serv_inc/thrhandler.h:23:16: warning: useless storage class specifier in empty declaration [enabled by default]

Is there any way to avoid this warning and achieve the same result? Am I doing it wrong and is there a more efficient solution to this problem?

This works for me:

typedef struct thread_pool thread_pool_t;
typedef struct single_thread single_thread_t;

struct thread_pool
{
    single_thread_t **tds;
};

struct single_thread
{
    thread_pool_t *tp;
};

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