Before this has written an article about the function pointer array, and today saw the application of communication engineering, copy down, as a reference!
http://blog.csdn.net/eliot_shao/article/details/8609259
1, the definition of data structure
typedef int (*io_detect_fuction) (void); typedef struct __IO_DETECT{INT id;io_detect_fuction fun;} Io_detect;
2. Type entity
Io_detect s_io_detect[]={{0x01, inputpowerdetect}, {0x02, InputPowerDetect1}, {0x03, Inputpowerdet Ect2}, {0x04, InputPowerDetect3}, {0x05, downbrokendectect}, {0x06, upbrokendetect}, {0x07, UpBrokenDetect1}, {0x08, opticaltransdetect}, {0x09, upoutputdetect}, {0x0A, Slavedcalarm}, {0x0B, slaveacalarm}, {0x0C, solarenergydetect}, {0x0D, Maininputpowe RDetect1}, {0x0E, MainInputPowerDetect2}, {0x0F, BackupInputPowerDetect1}, {0x10, BackupInputPowerDetect2}, {0 X11, Gzdtinputpowerdetect}, {0x12, gzdtopeicalalarmdect}, {0x13, bjdtslavedcalarm}, {0x14, bjdtupoutputdetect}, {0x15, bjdtslaveacalarm}, {0x16, dcalarm}, {0x17, acalarm}, {0x18, gsmctdowninputpowerdetect}, {0x19, CM Mbinputpowerdetect}, {0x1A, beijinginputpowerdetect}, {0x1B, beijingoutputpowerdetect}, {0x1C, cdmainputpowerdete Ct1}, {0x1D, DCAlarm1V}, {0x1E, acalarm1v}, {0x1F, bat13vdect}, {0x20, bat48vdect}, {0x21, REPORTK EY}, {0x22, InputPowerDetect4}, {0x23, OutputPowerDetect1}, {0x24, RePowerDetect1}, {0x25, A Clow_alarm}};
3. Function call
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;}
function pointer Array Engineering example