I have a a few callback functions. i need to register them as a list. And callback all the registered functions in a main after a certain task is done.

I am new to callback functions. Please shed some insight on this


register_callbackfunctions()//not too sure what goes in as the parameters here

//create the list of the functions


int main(){

 if( certain_task_is_done){

 //callback all the functions in the list that was registered



Recommended Answers

All 2 Replies

It's a very straightforward usage of function pointers. Here's a quikie example using a stack:

#include <stdio.h>
#include <stddef.h>

#define CALLBACK_MAX 10

typedef void (*callback_t)(void);

static callback_t callbacks[CALLBACK_MAX];
static size_t n = 0;

void register_callback(callback_t callback)
    if (n == CALLBACK_MAX)

    callbacks[n++] = callback;

void run_callbacks(void)
    while (--n < (size_t)-1)

void foo(void) { puts("foo!"); }
void bar(void) { puts("bar!"); }
void baz(void) { puts("baz!"); }

int main(void)


    return 0;

Thanks for the input. Really appreciate it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.