在这以前曾经写过一篇关于函数指针数组文章,今天又看到了通信工程的应用,拷贝下来,作为参考!
http://blog.csdn.net/eliot_shao/article/details/8609259
1、数据结构的定义
typedef int (*IO_DETECT_FUCTION)(void);
typedef struct __IO_DETECT
{
int id;
IO_DETECT_FUCTION fun;
}IO_DETECT;
2、类型实体
IO_DETECT s_IO_Detect[]=
{
{0x01, InputPowerDetect},
{0x02, InputPowerDetect1},
{0x03, InputPowerDetect2},
{0x04, InputPowerDetect3},
{0x05, DownBrokenDectect},
{0x06, UpBrokenDetect},
{0x07, UpBrokenDetect1},
{0x08, OpticalTransDetect},
{0x09, UpOutputDetect},
{0x0A, SlaveDCAlarm},
{0x0B, SlaveACAlarm},
{0x0C, SolarEnergyDetect},
{0x0D, MainInputPowerDetect1},
{0x0E, MainInputPowerDetect2},
{0x0F, BackupInputPowerDetect1},
{0x10, BackupInputPowerDetect2},
{0x11, GZDTInputPowerDetect},
{0x12, GZDTOpeicalAlarmDect},
{0x13, BJDTSlaveDCAlarm},
{0x14, BJDTUpOutputDetect},
{0x15, BJDTSlaveACAlarm},
{0x16, DCAlarm},
{0x17, ACAlarm},
{0x18, GSMCTDownInputPowerDetect},
{0x19, CMMBInputPowerDetect},
{0x1A, BeiJingInputPowerDetect},
{0x1B, BeiJingOutputPowerDetect},
{0x1C, CDMAInputPowerDetect1},
{0x1D, DCAlarm1V},
{0x1E, ACAlarm1V},
{0x1F, BAT13VDect},
{0x20, BAT48VDect},
{0x21, ReportKey},
{0x22, InputPowerDetect4},
{0x23, OutputPowerDetect1},
{0x24, RePowerDetect1},
{0x25, ACLow_Alarm}
};
3、函数调用
int IO_DetectFunction(int Id)
{
int i = 0;
int ret = 0;
for(i=0; i < sizeof(s_IO_Detect)/sizeof(IO_DETECT); i++)
{
if( s_IO_Detect[i].id == Id )
{
ret = s_IO_Detect[i].fun();
break;
}
}
return ret;
}