免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2099 | 回复: 5
打印 上一主题 下一主题

到底是函数还是函数指针 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 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;
}

论坛徽章:
0
2 [报告]
发表于 2010-09-07 17:27 |只看该作者
因为函数名和函数的地址的值一样, 打印一下thread和&thread就知道了.

论坛徽章:
1
CU十二周年纪念徽章
日期:2013-10-24 15:41:34
3 [报告]
发表于 2010-09-07 17:35 |只看该作者
和我这个问题差不多:http://bbs.chinaunix.net/thread-1781038-1-1.html

论坛徽章:
1
申猴
日期:2014-02-11 14:50:31
4 [报告]
发表于 2010-09-07 19:12 |只看该作者
你可以这样: ******thread

论坛徽章:
0
5 [报告]
发表于 2010-09-07 20:04 |只看该作者
我也不清楚

论坛徽章:
0
6 [报告]
发表于 2010-09-07 23:25 |只看该作者
thread=*thread=&thread
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP