2013-06-12 36 views
0

我试图在我的应用程序中实现一个线程池系统。我很喜欢每个线程都有一个指向我正在使用的线程池结构的指针。所以,基本上我有两种类似于以下的结构:两个结构互相包含时避免警告

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; 

独立于声明的顺序,编译器会给出一个错误。我在第一个结构之前解决了声明第二个结构,但是声明了它是空的。现在我没有得到任何错误,但我总是得到以下警告:

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

是否有任何方法可以避免此警告并获得相同的结果?我做错了,是否有更有效的解决方案来解决这个问题?

+1

这不能正常工作。没有'struct'关键字,应该有前向声明。请发布[SSCCE](http://sscce.org/)。 –

回答

6

这个工作对我来说:

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; 
};