void pointer as unknown argument type 和C回调函数问题
来源:互联网 发布:软件物理架构 编辑:程序博客网 时间:2024/06/07 10:07
// 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/
- void pointer as unknown argument type 和C回调函数问题
- void * 回调函数
- 【IOS异常汇总】之 implicit conversion of Object-C pointer type"NSString *" to C pointer type "const void *"
- 回调函数(c和指针)
- C回调函数和转换表
- C 回调函数
- 【c++】回调函数
- C 回调函数
- C回调函数
- [C] 回调函数
- C 回调函数
- C回调函数
- [C++]回调函数
- AS中使用回调函数
- warning: passing argument 2 of 'request_irq' from incompatible pointer type导致的中断申请失败和
- warning: passing argument 2 of 'request_irq' from incompatible pointer type导致的中断申请失败和
- Argument of type '(Foo::)(int,int)' does not match 'void (*)(int,int)'以及静态函数问题
- void pointer assignment in C
- nutz中获取request对象 LocalThread的使用
- flex模拟鼠标点击列表,弹出相关信息
- android 常用adb shell
- 贴个带分页的存储过程以备使用
- 《那些年啊,那些事——一个程序员的奋斗史》——05
- void pointer as unknown argument type 和C回调函数问题
- linux定时器使用范例
- ldd 的一个安全问题
- error: request for member ‘***’ in ‘***’, which is of non-class type ‘***’
- iPhone操作队列 VS Java线程池
- 判断字符串是否为Guid格式(C#)
- 堆排序,插入,删除,调整算法(大顶堆)
- sql 2005 開啓OpenRowset/OpenDatasource的辦法
- Asp.net控件开发学习笔记(二)-控件开发基础