Let me say that I am in this appeal:
main.c:
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
int iCanProcess (char* gimmeSmthToProcess);
int processingFunctionsCount = 0;
int (*(*processingFunctions)) (char*) = NULL;
int addProcessingFunction(int (*fct)(char*)) {
processingFunctionsCount++;
processingFunctions = realloc(processingFunctions,
sizeof(int (*)(char*))*ProcessingFunctionsCount);
processingFunctions[processingFunctionsCount-1] = fct;
}
int main(int argc, char *argv[]) {
char* dataToProcess = "I am some veeeery lenghty data";
addProcessingFunction(iCanProcess);
[ ... ]
for(unsigned int i = 0; i < processingFunctionsCount; i++) {
processingFunctions[i](dataToProcess);
}
free(processingFunctions);
return 0;
}
int iCanProcess (char* gimmeSmthToProcess) { ... }
somefile.c:
#include "header.h"
int aFunction(char* someDataToProcess) { ... }
header.h:
#ifndef HEADER_DEF
#define HEADER_DEF
extern int processingFunctionsCount;
extern int (*(*processingFunctions)) (char*);
int addProcessingFunction(int (*fct)(char*));
#endif
Is there any way using macros or any other trick I can add aFunctionfunction pointers to the array processingFunctionswithout changing, main.cor header.hevery time I need to add one?
The problem is not to change the array, since it can be easily redistributed, but NOT to change the function main(): there should be a way that I can know about the file that is here, and compiled, and get the function prototype from outsidemain()
I was thinking about using a preprocessor trick like this , but didn't seem to find a suitable way to do this ...
(Side-note: , , . , ( , , ), . , . , "", , , "", . main.c , .)
(Side-note 2: ... , , , , . )