借此可小小地实现C的面向对象

代码
1 #include <stdio.h>
2 #include <malloc.h>
3 #include <memory.h>
4  #define DECLARATION int (*ptr)(int x,int y)
5 #define DEFINITION(x,y) ptr(x,y)
6 int sum(int x,int y){
7 return(x+y);
8 }
9 void main()
10 {
11 int a,b,c;
12 typedef struct {
13 int r;
14 DECLARATION;
15 //int (*ptr)(int x,int y);
16 } mystr;
17 scanf("%d,%d",&a,&b);
18 //////////////////////////////////
19 //mystr stru;
20 //stru.ptr=sum;
21 //c=stru.ptr(a,b);
22 //printf("a=%d,b=%d,sum=%d\n",a,b,c);
23 ///////////////////////////////////
24
25 typedef mystr *struc;
26 struc stru;
27 stru=(struc)malloc(sizeof(mystr));
28 memset(stru,0,sizeof(mystr));
29 stru->ptr=sum;
30 c=stru->DEFINITION(a,b);
31 //c=stru->ptr(a,b);
32 printf("a=%d,b=%d,sum=%d\n",a,b,c);
33 memset(stru,0,sizeof(mystr));
34 free(stru);
35 }
36