What is the difference with "recursive" function and "callback" function?
Printable View
What is the difference with "recursive" function and "callback" function?
A recursive function is one that calls itself eg:
It has no reference point ot the function that called it.Code:Public Function foo(arg as Variant)
'do some stuff (like the exit case)
foo(arg)
Next Function
On the other hand a call back function knows which function called it, and can talk back to that function (its a bit of a theoretical concept, and I can't provde a decnt sample)
- gaffa
Just like gaffa said a recursive function calls itself. The most usual example is a function that count the faculty of a number:
A call back function is when you pass a pointer to a function as an argument to an other function.Code:Public Function Faculty(Number As Integer) As Long
'The facutly of 1 or 0 is 1
'so that's the exit point
If Number = 1 Or Number = 0 Then
Faculty = 1
Exit Function
End If
Faculty = Number * Faculty(Number - 1)
End Function
The function you call in turn calls the function you pass as an argument.
A lot of API functions use callback functions. A few of them is:[*]EnumWindows[*]EnumChildWindows[*]EnumTimeFormats[*]EnumClipboardFormats[*]...and so on...
Before VB5 you couldn't use any of these functions because VB didn't have a way for passing a function pointer.
But Microsoft introduced the AddressOf keyword in VB5.
Best regards