Monday, May 21, 2012

Function pointer


FORMAT:
int realFunc(<params>) { return 0; }
int (*funcName)(<params>);
funcName = realFunc; 

EXAMPLES:
int lbkStubFunc(int port, int mode) { return 0; }

int (*drv_eth_port_set_loopback)(int port, int mode) = lbkStubFunc;

or
drv_eth_port_set_loopback = lbkStubFunc;


FORMAT using typedef: 
Int stub(<API interface>) { return 0; }
typedef int (*FUNCPTR) (<API interface>);

FUNCPTR tmp;
tmp = (FUNCPTR) stub;

No comments:

Post a Comment