您的位置:首页 > 其它

有关函数指针的问题

2010-09-01 17:11 162 查看
下面的三个输出是一样的,即函数名字作为一个地址,作为一个常量来使用

所以对这个函数名做&或者*操作是没有意义的. 其值都是一样的.

 

但是如果要使用一个函数指针的变量,就需要使用* 来调用函数.

这个问题解决了我的一个困惑:

 

 

#include <stdio.h>
int hello()
{
return 0;
}
int main()
{
printf("%p/n",&hello);
printf("%p/n",*hello);
printf("%p/n",hello);

}
~
 

 

 

下面是解决的困惑,即对pthread_create()函数使用的时候,第三个参数

可以使用下面三种形式,编译器认为没有问题:

 pthread_create(&thread_id,NULL,printx,NULL);

 pthread_create(&thread_id,NULL,&printx,NULL);

 pthread_create(&thread_id,NULL,*printx,NULL);

 

函数原型为int pthread_create(pthread_t * thread, pthread_attr_t * attr, void * (*start_routine)(void *), void * arg) 

 

 

#include <stdio.h>
#include <pthread.h>
void *printx(void *unset)
{
while (1)
{
fputc('x',stderr);
}
return NULL;
}
int main()
{
pthread_t thread_id;
pthread_create(&thread_id,NULL,printx,NULL);
while (1)
fputc('o',stderr);
return 0;
}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  thread null 编译器