Callback (computer programming)
Appearance
In computer science, a callback is a concept, which allow a low level layer to call a function from a hight level layer, when usually, the hight level call the low level layer.
Use
When is it used? (Concrete programs)
Languages
This should be don using languages such as th C language.
With object oriented languages, this should naturally be done throw an object, and inheritence.
Example
Example code
l.c
void counter ( void (*cb)(int) ) { int i; for (i=15; i<20;i++) { cb(i); } }
h.c
printHex (int i) { printf ("%x\n",i); }
printDec (int i) { printf ("%d\n",i); }
int main () { counter (printDec); counter (printHex); }
Example result
15 16 17 18 19 f 10 11 12 13