码迷,mamicode.com
首页 > 其他好文 > 详细

头文件中结构体互相引用的问题

时间:2017-01-25 18:50:08      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:vol   修改   error   div   文件中   thread   ati   class   actual   

先上代码看下错误的例子:

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;

 

头文件中结构体互相引用的问题

标签:vol   修改   error   div   文件中   thread   ati   class   actual   

原文地址:http://www.cnblogs.com/biglucky/p/6349862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!