-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include <unistd.h>
-
-
typedef void (*Print) (void *);
-
typedef int (*Sum) (void * , void *);
-
-
struct func{
-
Print print;
-
Sum sum;
-
};
-
-
-
void print_char(void *data)
-
{
-
char *ch = (char *)data;
-
-
printf("func:%s ,%sn",__FUNCTION__, ch);
-
}
-
-
int sum_int(void *a, void *b)
-
{
-
int sum = *(int *)a + *(int *)b;
-
-
printf("func:%s, %dn",__FUNCTION__, sum);
-
-
return sum;
-
}
-
-
int main(int argc, char *argv[])
-
{
-
struct func f1;
-
int sum = 0;
-
int a = 5, b = 6;
-
-
f1.print = print_char;
-
f1.sum = sum_int;
-
-
-
f1.print("hello,world");
-
sum = f1.sum(&a, &b);
-
-
printf("sum:%dn", sum);
-
-
return 0;
-
}
运行结果:
func:print_char ,hello,world
func:sum_int, 11
sum:11
参考:
《系统程序员成长计划》
阅读(827) | 评论(0) | 转发(0) |