LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1012|回复: 3

Callback 函数

[复制链接]
发表于 2006-8-11 19:22:45 | 显示全部楼层 |阅读模式

  1. #include <stdio.h>

  2. typedef void (*pDesc)(void);
  3. typedef void (*pFee)(long);

  4. void Desc()
  5. {
  6.     printf("Address: %s\n", "I come from BTW");
  7. }

  8. void Fee(long pLong)
  9. {
  10.     printf("Fee: %ld\n",pLong);
  11. }

  12. void Dothing(char* pName, pDesc, pFee, int pScore)
  13. {
  14.     printf("%s\n", pName);
  15.     pDesc();
  16.     pFee(100);
  17.     printf("%d\n", pScore);
  18. }

  19. int main()
  20. {
  21.     pDesc pDescstu1;
  22.     pFee  pFeestu1;
  23.     pDescstu1 = Desc;
  24.     pFeestu1 = Fee;

  25.      Dothing("Ascort", pDescstu1, pFeestu1, 60);

  26.     return 0;
  27. }
  28. [root@root Stuff]# ./a.out
  29. Ascort
  30. 60
  31. [root@root Stuff]#
复制代码

回调函数没有打印呢? 在sqlite3_exec()中的回调函数的参数在sqlite3_exec()的实现中给出的。
发表于 2006-8-11 19:38:35 | 显示全部楼层
这是什么方法 ?  .. 函数定义中第 二,三 个参数留空? ..把类型名当参数使用??..

牛X



回这个帖是第5次修改了,, 而且程序也能通过编译运行 不崩溃.....
回复 支持 反对

使用道具 举报

发表于 2006-8-11 20:12:40 | 显示全部楼层
  1. #include <stdio.h>
  2. typedef void (*pDesc)(void);
  3. typedef void (*pFee)(long);
  4. void Desc()
  5. {
  6.         printf("Address: %s\n", "I come from BTW");
  7. }
  8. void Fee(long pLong)
  9. {
  10.         printf("Fee: %ld\n",pLong);
  11. }
  12. void Dothing(char* pName, pDesc desc, pFee fee, int pScore)
  13. {
  14.         printf("%s\n", pName);
  15.         desc();
  16.         fee(100);
  17.         printf("%d\n", pScore);
  18. }
  19. int main()
  20. {
  21.         pDesc pDescstu1;
  22.         pFee  pFeestu1;
  23.         pDescstu1 = Desc;
  24.         pFeestu1 = Fee;
  25.         Dothing("Ascort", Desc, Fee, 60);
  26.         return 0;
  27. }
复制代码
  1. rf@RemoteFish:/dev/shm$ gcc a.c
  2. rf@RemoteFish:/dev/shm$ ./a.out
  3. Ascort
  4. Address: I come from BTW
  5. Fee: 100
  6. 60
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-8-12 15:30:50 | 显示全部楼层
It suddently to reminder  me that  the prototype of the third parameter in  the sqlite3_exec(...) be defined like below:

  1. typedef int (*sqlite3_callback)(int*, char**, char**)
复制代码

then the prototype of the sqlite3_exec() be defined like below:

  1. int sqlite3_exec(sqlite3**, sqlite3_callback, char*, char** zErrMsg)
复制代码

however, the implementation of sqlite3_exec() be implemented likes this

  1. int sqlite3_exec(sqlite3** _db, sqlite3_callback xCallback, char* , char** zErrMsg)
  2. {
  3.    xCallback(...)
复制代码

Tks, your simple but very useful help told me that what does a good man shoud be likes
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表