I am building a app with lots of files that use the same "main" functionality
for example:
file1 as 3 functions called: doX, doY, doZ file2 as 1 function called: abc file3 as 10 functions called: a1, a2, a3 etc...
i have a main program that process these functions in order to generate and calculate correct data.
the problem i have is the "main" program does not know which functions to run so i was thinking to create a common function for all my files that will return the list of the functions to run in a specific order
but for some reason it does not work
heres my sample code
// in main.h
#include <stdio.h>
// in file1.c
// #include ...
int doX() {
// do stuff
return 1;
}
int doY() {
// do stuff
return 1;
}
int * get_tasks() {
int (*task[2])() = { };
int id = 0;
id++; task[id] = doX;
id++; task[id] = doY;
return *task;
}
// main.c
#include "main.h"
int main () {
int * pl;
int i, success = 0;
printf("do stuff");
pl = get_tasks();
for(i = 0; i < 2; i++) {
success += *(pl[i])();
}
printf("success = %d", success);
}
when i run: gcc *.c
i get:
test.c: In function ‘get_tasks’:
test.c:24:3: warning: return from incompatible pointer type [enabled by default]
return *task;
^
test.c: In function ‘main’:
test.c:38:24: error: called object is not a function or function pointer
success += *(pl[i])();
^
how can i fix this?
Pointer to function is not int* (return type of get_tasks)then what I should use?