Chinaunix

标题: 到底是函数还是函数指针 [打印本页]

作者: general1028    时间: 2010-09-07 17:21
标题: 到底是函数还是函数指针
最近写了个小测试程序,
发现针对pthread_create函数的第3个函数,传入无论是函数还是函数的引用结果是一样的。请大拿帮回答。
#include <stdio.h>
#include <pthread.h>

void* thread(void *)
{
int i;
for(int i=0;i<3;i++)
{
printf("this is a thread.\n");
}
}

int main(void)
{
pthread_t id;
int i,ret;
ret=pthread_create(&id,NULL,thread,NULL);  //这里不管用thread还是&thread都是一样的
if(ret!=NULL)
{
  printf("create error");
  return 1;
}
for(int i=0;i<3;i++){
printf("this is main process");
}
pthread_join(id,NULL);
return 0;
}
作者: mmx_craft    时间: 2010-09-07 17:27
因为函数名和函数的地址的值一样, 打印一下thread和&thread就知道了.
作者: ecjtubaowp    时间: 2010-09-07 17:35
和我这个问题差不多:http://bbs.chinaunix.net/thread-1781038-1-1.html
作者: chenzhanyiczy    时间: 2010-09-07 19:12
你可以这样: ******thread
作者: rain_fish    时间: 2010-09-07 20:04
我也不清楚
作者: pengjianbokobe    时间: 2010-09-07 23:25
thread=*thread=&thread




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2