This is the lab building on the previous callback debug example, I did not submit the validation, but running on-premises without any problems, and no warning:
#include <stdio.h> #define MAX 3typedef Int (*alarm) (int type); alarm Alarm_list[max];int index = 0;void Register_ala RM (alarm a); int hit_alarm (int index), void Register_alarm (alarm a) { alarm_list[index++] = A;} int hit_alarm (int index) { if (Index < 0 | | index >= MAX) return 1; (*alarm_list[index]) (index); return 0;} int alarm1 (int type) { printf ("one:%d\n", type); return 0;} int alarm2 (int type) { printf ("two:%d\n", type); return 0;} int alarm3 (int type) { printf ("three:%d\n", type); return 0;} int main{ register_alarm (ALARM1); Register_alarm (ALARM2); Register_alarm (ALARM3); Hit_alarm (0); Hit_alarm (1); Hit_alarm (2); return 0;}
Write another example of implementing a callback:
#include <stdio.h>typedef int (*__callback__) (void* type_param), void Func_register (__callback__ func, void* param), void Func_register (__callback__ func, void* param) { (*func) (param);} Custom Function int My_func (void* param) { printf ("Param is%d\n", (int*) param); return 0;} int main{ //Custom function is invoked as a function parameter func_register (My_func, (void*) 5); return 0;}
C + +-CallBack