有关函数指针的问题
2010-09-01 17:11
162 查看
下面的三个输出是一样的,即函数名字作为一个地址,作为一个常量来使用
所以对这个函数名做&或者*操作是没有意义的. 其值都是一样的.
但是如果要使用一个函数指针的变量,就需要使用* 来调用函数.
这个问题解决了我的一个困惑:
下面是解决的困惑,即对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> 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; }
相关文章推荐
- 有关函数指针的问题(转载)
- 结构体指针作为函数参数传递却无法传值的有关问题
- 有关scanf的输入函数的一些问题
- c++之指针作为函数参数传递的问题
- 指针作为函数参数的问题
- 约瑟夫环问题的PHP实现 使用PHP数组内部指针操作函数
- c++之指针作为函数参数传递的问题
- 有关指针方面的一些问题!
- partial_sort()和nth_element() 两个和排序有关的函数的性能问题
- C语言中有关外部函数调用的问题
- 有关函数返回值类型的问题
- c/c++使用指针做函数返回值和指针作函数参数问题
- 【java基础】引用类型数组初始化中,setter和getter函数空指针问题
- QT信号槽的六个优点(虽然直接调用函数也可解决问题,但要在具体的函数中传递指针,多对一和解除关系也够麻烦的)
- 向普通函数传递类成员函数指针的问题
- 函数调用缺少参数列表;请使用“&Student::Printf”创建指向成员的指针 问题解析
- 函数参数的传递问题(指针的指针)【想在函数中分配内存】(指针做参数,即可做输入参数也可做输出参数)
- C++指针作为函数的参数进行传递时注意的问题
- 翻译《有关编程、重构及其他的终极问题?》——28.如果你可以使用简单的函数就不要使用宏
- 指针作为函数参数问题