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.

difference between callback concept and normal calling concept

Status
Not open for further replies.

ahmedsaber

Junior Member level 1
Junior Member level 1
Joined
Mar 11, 2013
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Al Jizah, Egypt
Activity points
1,449
hi all
I'm so confused

we know that all functions defined as global so we can call and use any function inside any block without passing it as argument

why we use Function callback concept while we can use a function inside any function without passing it

so why we use callback concept ?
 

If you have limited memory space, then it is efficient usage to declare variables only within the function which uses them, because the variable ceases when the function exits, allowing memory to be released.

Another reason is in the case of a recursive function (a function which calls itself). Then you cannot use a global variable. You must create multiple versions of a variable, for each time the function calls itself.

Or suppose a different programmer is called on to make necessary revisions (because the original programmer is unavailable). The new guy might prefer to create a new function with variables unique to that function. This avoids any hassle with existing global variables, or risk of overwriting them, or any interference with them.

In most cases it might not make a difference whether you declare a variable as global, or whether you declare it only within the function which uses it.
 

Normal function:

Program ----> function -----> program

callbackback function:

Program -----> function -----> maybe another function ----->Program

It is similar but not identical to a nested function because the "another function" may bypass the hierarchy and go back to the program directly. It's useful in real time applications because the return to the program may not be held up by having to traverse each level of the hierarchy before returning. It implies that the return address is passed as a parameter along the hierarchy so it is known no matter how deep the nesting is. 'function' may be triggered by an event in the same way as an interrupt.

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top