返回信息流zebra源码中有关线程管理的源码中里有一结构体
struct thread
{
unsigned char type; /* thread类型,共有六种 */
struct thread *next; /* 指向下一thread的指针,双向链表 */
struct thread *prev; /*指向前一thread的指针*/
struct thread_master *master; /* 指向该thread所属thread_master结构体的指针 */
int (*func) (struct thread *); /* event类型thread的函数指针 */
void *arg; /* event类型thread的参数 */
union {
int val; /* event类型thread的第二个参数*/
int fd; /* read/write类型thread相应的文件描述符 */
struct timeval sands; /* 该thread的剩余时间,timeval类型,此结构体定义在time.h中,有两个元素,秒和微秒 */
} u;
RUSAGE_T ru; /* 详细用法信息,RUSAGE这个宏在该thread有用法描述时定义为rusage类型,描述其详细进程资源信息,没有用法描述时定义为timeval类型 */
};
请问int (*func) (struct thread *); /* event类型thread的函数指针 */
void *arg; /* event类型thread的参数 */
什么意思呢?
void 这不是无返回值的意思吗?怎么能用来定义变量呢?
这是一条镜像帖。来源:北邮人论坛 / cpp / #36116同步于 2010/2/26
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
[求助]int (*func) (struct thread *)怎么解释?
salooloo
2010/2/26镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
void* 是一个指针变量,可以用来分配空间,转换成其他的类型。例如:
void* v; int iv=97;
v = (void*)&iv;
printf("%c\n",*(char*)v); // a
printf("%d\n",*(int*)v); // 97
void* 一般起到屏蔽的作用,让外界不能看到具体的结构类型,如果需要的话,强制转换成所需要的类型就可以了。
【 在 SuK 的大作中提到: 】
: void* 是一个指针变量,可以用来分配空间,转换成其他的类型。例如:
: void* v; int iv=97;
: v = (void*)&iv;
: ...................
那请问 结构体的一个成员怎么可以是一个函数呢?
【 在 jokerlee 的大作中提到: 】
: 名为func的函数指针, 指向参数为struct thread *、返回值为int的函数