1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Help Needed on C Programming

Discussion in 'C' started by clc, Dec 14, 2011.

  1. clc

    clc New Member

    Hi,
    Does anyone know what does "req.dataRetHandler = SetFOO" means in the following code?

    Code:
    typedef struct 
    {
     
      unsigned char command;                           
      unsigned int (*dataRetHandler)(unsigned char, unsigned char);
     
    } queue_t;
     
    unsigned char PushInOQ(unsigned char channel, queue_t *pReq )
    {
         printf("Command = %02X\n",pReq->command);
         return 0;
    }
     
    unsigned int SetFOO(unsigned char channel, unsigned char uData)
    {
        queue_t req;
        unsigned char result = 0;
        req.command = 0x04;
        result = PushInOQ( 0, &req);
        return (0);
    }
    void main(void)
    {
        queue_t req;
        unsigned char result = 0;
        req.command = 0x01;
        req.dataRetHandler = SetFOO;
        result = PushInOQ( 0, &req);
    }
    

    Thanks in advance.

    Regards
     
  2. xpi0t0s

    xpi0t0s Mentor

    req.dataRetHandler is a function pointer, so it sets req.dataRetHandler to the address of the function SetFOO(). So you can call req.dataRetHandler as if it were a function (using function pointer syntax, of course) and that way you don't have to have a big if/else if ladder in the code deciding which of multiple functions to call.

    But the code in its current form doesn't actually call req.dataRetHandler, so in effect the answer to your question is "nothing significant".
     

Share This Page