Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1299880
  • 博文数量: 548
  • 博客积分: 7597
  • 博客等级: 少将
  • 技术积分: 4224
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-15 13:21
个人简介

嵌入式软件工程师&&太极拳

文章分类

全部博文(548)

文章存档

2014年(10)

2013年(76)

2012年(175)

2011年(287)

分类: LINUX

2013-04-22 17:18:15


点击(此处)折叠或打开

  1. #include <stdio.h>

  2. struct board {
  3.     char name[16];
  4.     char file[16];
  5. };

  6. struct test_opera{
  7.     struct board *bd;
  8.     int (*namtest)(void);
  9.     int (*filtest)(void);
  10. };

  11. struct vars{

  12.     struct board *board;
  13.     struct test_opera *pto;

  14. };

  15. #define NELEM(x) (sizeof(x) / sizeof((x)[0]))

  16. int znamopera(void);
  17. int zfilopera(void);
  18. int xnamopera(void);
  19. int xfileopera(void);


  20. struct vars variables = {};
  21. struct vars * const v = &variables;


  22. //==========================================//

  23. struct board ze = {
  24.     .name = "zerong",
  25.     .file = "/zerong",
  26. };

  27. struct board xiao = {
  28.     .name = "xiaoming",
  29.     .file = "/xiaoming",
  30. };


  31. struct test_opera gMethods[] = {

  32.     {&ze, znamopera, zfilopera},

  33.     {&xiao, xnamopera, xfileopera},

  34. };



  35. int znamopera(void)
  36. {
  37.     printf("znamopera1\n");
  38. }


  39. int zfilopera(void)
  40. {
  41.     printf("znamopera1\n");
  42. }

  43. int xnamopera(void)
  44. {
  45.     printf("xnamopera2\n");
  46. }

  47. int xfileopera(void)
  48. {
  49.     printf("xfileopera2\n");
  50. }


  51. struct test_opera *init_pto(char pto_name[16])
  52. {
  53.     int i;
  54.     struct test_opera *pto = NULL;

  55.     for (i = 0; i < NELEM(gMethods); i++)
  56.     {
  57.         printf("sz = %d\n", NELEM(gMethods));
  58.         pto = &gMethods[i];

  59.         if (!pto || !(pto->bd))
  60.             continue;
  61.         if (!strcmp(pto_name, pto->bd->name)) {
  62.             v->pto = pto;
  63.             v->board = pto->bd;
  64.             break;
  65.         }
  66.     }

  67.     return v->pto;
  68. }


  69. int main(void)
  70. {
  71.     struct test_opera *pto;

  72.     pto = init_pto("zerong");
  73.     pto->namtest();
  74.     pto->filtest();

  75.     return 0;
  76. }

阅读(1043) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~