#include <stdio.h>
#define PF_ID 10
enum
{
ID1 = 10,
ID2,
ID3,
};
char *message = "message";
int create(int fd,char *name)
{
if(fd == 10)
{
printf ("I am create fd = %d,name = %s\n",fd,name);
}
return 1;
}
int output (int fd,char *name)
{
printf("I am output fd =%d,name = %s\n",fd,name);
return 1;
}
int output_2 (int fd,char *name)
{
printf("I am output_2 fd = %d,name = %s\n",fd,name);
}
struct test_1
{
int (*output)(int fd,char *name);
};
struct test
{
int id;
char name[50];
int (*print)(int fd,char *name);
};
static struct test des ={
.id= PF_ID,
.name ="frank",
.print = create,
};
struct test_1 table[] = {
[ID1] = {.output = output},
[ID2] = {.output = output_2},
};
int main()
{
printf("des.PF_ID=%d\n",des.id);
printf("des.message= %s\n",des.name);
des.print(PF_ID,message);
table[ID2].output(PF_ID,"table ID2");
table[ID1].output(PF_ID,"table ID1");
}
|