use*_*011 5 c struct function-pointers
得到以下数据结构:
typedef struct
{
lamp *lamp;
unsigned char a;
unsigned char b;
unsigned char c;
unsigned char d;
unsigned char e;
void (*func)(struct event *);
} event;
Run Code Online (Sandbox Code Playgroud)
结构中的最后一行应该是一个指向函数的指针,返回类型为void,指向事件的指针作为参数,例如:
void function(event *evt);
Run Code Online (Sandbox Code Playgroud)
虽然,我得到以下警告信息:"它的范围只是这个定义或声明,可能不是你想要的".这是对还是错?
您的结构需要需要像这样定义:
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`
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
923 次 |
| 最近记录: |