Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to understand this function?

Status
Not open for further replies.

love_electronic

Member level 5
Joined
Nov 16, 2010
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,964
Hi guys
in a program i am unable to understand a function. Kindly help me to understand how it is working?

in a program at some point a function is called
Code:
PIT_SetupCallBack(Pit0CallBack);

Code:
void PIT_SetupCallBack( T_PIT_Callback CallBack )
{
	PIT_Callback[0] = CallBack;
}

Pit0CallBack will toggle an led
Code:
void Pit0CallBack(void)
{
    /* toggle blue led, indicating PIT timer0 interrupt */
    LED2_Toggle();
}

and a typedef is defined in a .h file like
Code:
typedef void (*T_PIT_Callback)(void);

Can you tell me what is the purpose of typedef void(*something)(void)? How does it works? from where to learn these kinds of functions?
How these routines are working?
 

Just a pointer to the function. For example, void (* function) (void) can be assigned to any function like void (void). If parameters needed, should be used like that void (* function) (uint8_t value); and e.t.c.
Unussigned pointer goes to 0, so normally you shoud check it before execute: if (function) function();
 

from where to learn these kinds of functions?
Review your favorite C programming text book about function pointers, e.g. Kernighan & Ritchie 2nd, paragraph 5.11 Pointers to Functions.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top