5

得到以下数据结构:

typedef struct
{
    lamp *lamp;
    unsigned char a;
    unsigned char b;
    unsigned char c;
    unsigned char d;
    unsigned char e;
    void (*func)(struct event *);
} event;

结构内的最后一行应该是一个指向函数的指针,该函数返回类型为 void,并带有指向事件的指针作为参数,例如:

void function(event *evt);

虽然,我收到以下警告消息:“它的范围只是这个定义或声明,这可能不是你想要的”。这是对还是错?

4

1 回答 1

7

您的结构需要像这样定义:

typedef struct event  // <<< note the `event` tag here
{
    lamp *lamp;
    unsigned char a;
    unsigned char b;
    unsigned char c;
    unsigned char d;
    unsigned char e;
    void (*func)(struct event *);
} event;              // <<< you can still keep `event` as a typedef
                      //     which is equivalent to `struct event`
于 2013-03-18T11:19:44.940 回答