【问题标题】:C typedef pointer to func with argument pointer to structC typedef 指向 func 的指针和指向 struct 的参数指针
【发布时间】:2018-04-13 13:59:02
【问题描述】:

我需要将typedef p* 定义为一个函数,它的参数是p*struct

typedef void (*tFunc_t)(pTask_t); // warning: parameter names (without types) in function declaration

typedef struct Task_t {
    struct Task_t *Next; 
    tFunc_t Task; 

}Task_t, *pTask_t;

由于函数是struct 的一部分,我如何编写func typedef 以便编译器不再发出警告?

谢谢!

很好,谢谢@R Sahu!这很顺利。

struct Task_t;
    typedef void (*tFunc_t)(struct Task_t*); 
    typedef struct Task_t {
        struct Task_t *Next;
        tFunc_t Task;       
    }Task_t, *pTask_t;

【问题讨论】:

    标签: c


    【解决方案1】:

    您可以使用struct 的前向声明来做到这一点。

    // Forward declaration of the struct
    struct Task_t;
    typedef void (*tFunc_t)(struct Task_t*);
    

    您无需使用pTask_t 为函数指针定义typedef

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-26
      • 2016-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      相关资源
      最近更新 更多