首页 > 代码库 > 头文件中结构体互相引用的问题
头文件中结构体互相引用的问题
先上代码看下错误的例子:
typedef struct _thread{ int id; /* friendly id */ pthread_t pthread; /* pointer to actual thread */ thpool_handle_t thpool_p; /* access to thpool */} thread_t;/* Threadpool * threadpool has many threads, and he should to access each threads, threads pointer array to save all threads pointer */typedef struct _thpool{ thread_t** threads; /* pointer to threads */ volatile int num_threads_alive; /* threads currently alive */ volatile int num_threads_working; /* threads currently working */ pthread_mutex_t thcount_lock; /* used for thread count etc */ jobqueue* jobqueue_p; /* pointer to the job queue */} thpool_t, *thpool_handle_t;
编译提示:
./include/thread_pool.h:31:5: error: unknown type name ‘thpool_handle_t’
修改如下解决:
struct _thread;struct _thpool;typedef struct _thread thread_t;typedef struct _thpool thpool_t, *thpool_handle_t;typedef struct _thread{ int id; /* friendly id */ pthread_t pthread; /* pointer to actual thread */ thpool_handle_t thpool_p; /* access to thpool */} thread_t;/* Threadpool * threadpool has many threads, and he should to access each threads, threads pointer array to save all threads pointer */typedef struct _thpool{ thread_t** threads; /* pointer to threads */ volatile int num_threads_alive; /* threads currently alive */ volatile int num_threads_working; /* threads currently working */ pthread_mutex_t thcount_lock; /* used for thread count etc */ jobqueue* jobqueue_p; /* pointer to the job queue */} thpool_t, *thpool_handle_t;
头文件中结构体互相引用的问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。