function pointer Array Engineering example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.