[英]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;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.