void pointer as unknown argument type 和C回调函数问题
2011-06-17 17:05
225 查看
// FILE NAME:c_callback_funtions_void.c
#include <stdio.h>
#include <stdlib.h> // exit()
#include<string.h> // bzero()
#include<sys/time.h>
#include<sys/types.h>
#include<unistd.h>
typedef void TaskFunc(void* argument);
void do_something(TaskFunc* proc, void* argument)
{
(*proc)(argument); // 函数这里调用。
}
void funtion_1(void* argument)
{
char* p = (char*)argument;
printf("funtion_1 print is : %s/n",p);
}
typedef struct _FOR_FUNTION2
{
int a;
char str[20];
}FOR_FUNTION2;
void funtion_2(void* argument)
{
FOR_FUNTION2 *p = (FOR_FUNTION2*)argument;
printf("funtion_2 print is : %d,%s/n",p->a,p->str);
}
int main(int argc,char* argv[])
{
char str1[] = "this is funtion_1";
/* 第一种方法 */
void* argument_fun_1 = (void*)str1;
do_something(&funtion_1,argument_fun_1);
/* 第二种方法 */
do_something(&funtion_1,(void*)str1);
FOR_FUNTION2* p = (FOR_FUNTION2*)malloc(sizeof(FOR_FUNTION2));
p->a = 100;
memcpy(p->str,"this is funtion_2/0",sizeof("this is funtion_2"));
/* 第一种方法 */
void* argument_fun_2 = (void*)p;
do_something(&funtion_2,argument_fun_2);
/* 第二种方法 */
do_something(&funtion_2,(void*)p);
printf("%d/n",sizeof("test")); // 注意这里是等于5
return 0;
}
http://www.newty.de/fpt/intro.html http://www.cplusplus.com/forum/general/158/
#include <stdio.h>
#include <stdlib.h> // exit()
#include<string.h> // bzero()
#include<sys/time.h>
#include<sys/types.h>
#include<unistd.h>
typedef void TaskFunc(void* argument);
void do_something(TaskFunc* proc, void* argument)
{
(*proc)(argument); // 函数这里调用。
}
void funtion_1(void* argument)
{
char* p = (char*)argument;
printf("funtion_1 print is : %s/n",p);
}
typedef struct _FOR_FUNTION2
{
int a;
char str[20];
}FOR_FUNTION2;
void funtion_2(void* argument)
{
FOR_FUNTION2 *p = (FOR_FUNTION2*)argument;
printf("funtion_2 print is : %d,%s/n",p->a,p->str);
}
int main(int argc,char* argv[])
{
char str1[] = "this is funtion_1";
/* 第一种方法 */
void* argument_fun_1 = (void*)str1;
do_something(&funtion_1,argument_fun_1);
/* 第二种方法 */
do_something(&funtion_1,(void*)str1);
FOR_FUNTION2* p = (FOR_FUNTION2*)malloc(sizeof(FOR_FUNTION2));
p->a = 100;
memcpy(p->str,"this is funtion_2/0",sizeof("this is funtion_2"));
/* 第一种方法 */
void* argument_fun_2 = (void*)p;
do_something(&funtion_2,argument_fun_2);
/* 第二种方法 */
do_something(&funtion_2,(void*)p);
printf("%d/n",sizeof("test")); // 注意这里是等于5
return 0;
}
http://www.newty.de/fpt/intro.html http://www.cplusplus.com/forum/general/158/
相关文章推荐
- Argument of type '(Foo::)(int,int)' does not match 'void (*)(int,int)'以及静态函数问题
- 安卓问题报告小记(六):Type Unknown error: java.lang.NullPointerException
- 安卓问题报告小记(六):Type Unknown error: java.lang.NullPointerException
- 关于SDK回调Qt函数的问题
- 问题函数关于SDK回调Qt函数的问题
- Flask 应用程序外部可见问题: typeerror run() got an unexpected keyword argument 'host'.
- iOS实战演练之Unknown type name 'UIColor" 的问题
- windows7下解决caffe check failed registry.count(type) == 1(0 vs. 1) unknown layer type问题
- 解决java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList的问题
- msync(void *addr,size_t len, int flags) 函数的使用问题
- ajax回调函数执行顺序带来的同步异步问题
- 求教 android 混淆时出现Unknown verification type [*] in stack map frame问题
- “passing argument 2 0f “request_irq” from incompatible pointer type”导致中断申请失败和模块无法加载
- spring boot jpa-java.lang.IllegalArgumentException: Not a managed type异常问题解决方法
- 路由软件 zebra-0.95a 在linux下面编译出现问题的解决(error: dereferencing pointer to incomplete type)
- Scrapy框架中通过爬虫文件中的parse函数中的callback无法回调别的函数的问题
- 关于JQuery的post回调函数不执行问题
- Ext.data.DirectStore中DirectAction的回调函数问题
- 路由软件 zebra-0.95a 在linux下面编译出现问题的解决(error: dereferencing pointer to incomplete type)
- JavaScript的回调函数内部this的指向问题以及四种绑定this指向的方法