Function Pointer

Discussion in 'Programmer's Corner' started by aamirali, Nov 20, 2012.

  1. aamirali

    Thread Starter Member

    Feb 2, 2012
    415
    1
    Function Pointer

    Code ( (Unknown Language)):
    1.  
    2. #define IAP_LOCATION 0x1FFF1FF1
    3. typedef void (*IAP) (   unsigned int command[],
    4.                         unsigned int result[] );
    5. static const IAP iap_entry = (IAP) IAP_LOCATION;
    6.  
    7. void writeEEPROM( uint16_t* eeAddress, uint8_t* buffAddress, uint32_t byteCount )
    8. {  
    9.     unsigned int command[5], result[4];
    10.  
    11.     command[0] = 61;                  
    12.     command[1] = (uint32_t) eeAddress;
    13.     command[2] = (uint32_t) buffAddress;
    14.     command[3] = byteCount;            
    15.     command[4] = 375;
    16.    
    17.     /* Invoke IAP call...*/
    18.     iap_entry(command, result);
    19.     if (0 != result[0])
    20.     {
    21.         //Trap error
    22.         while(1);
    23.     }
    24.     return;
    25. }
    26.  
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    is there a question?
     
  3. aamirali

    Thread Starter Member

    Feb 2, 2012
    415
    1
    I couldn't complete my query,sry 4 dat.


    What does below line do in above code:

    static const IAP iap_entry = (IAP) IAP_LOCATION;
     
  4. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Ohhhhhhh. mobile device??

    (IAP) is a typecast. IAP location is a numerical value.

    "static const" is very compiler specific.
    But normally const means the particle will be placed in ROM.
     
  5. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,017

    No one is going to be able to help you if you can't give full details of your issue. If you are having trouble with English then perhaps you should try and find a friend or co worker help you to write your question.
     
  6. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    static const - let's think of that as ROM for the time being.

    so it is

    rom IAP iap_entry = .....

    this is misleading, as IAP and iap_entry can be confused for each other by people who don't know much C.

    It means, an IAP structure named iap_entry is declared, and placed in ROM.

    it is also assigned a value: IAP_LOCATION (which is simply numeric).
    This value is casted into IAP using a typecast: (IAP).

    I hope this helps.
     
Loading...