I am trying to create a modular interface in my C project, which will allow me to create source files selectively and add and delete without the need to change any components of the project core. I searched the entire network for a method on how to do this and cannot find anything.
My assumption at this stage will include something along the lines of each module that has its own source and header files (module_1.c, module_1.h, module_2.c, module_2.h, etc.). For each module, there probably should be a structure containing pointers to the necessary functions, such as:
struct module_def {
char *name;
void (*module_init) (void);
void (*module_shutdown) (void);
};
I believe that an array of these definition structures would then have to be accessible using the main code. I just don’t know how to create such an array (or something similar) automatically using the list of included modules without resorting to a messy script that creates a new source file containing a list of all structures during the build process.
At the very least, I believe this should work.
Ultimately, I’m looking for a way to create a modular coding interface in C that will allow individual modules (source or object files, it doesn’t matter) to selectively bind during assembly and be called by the main application. This is for an embedded solution, so dynamic loading, shared libraries, etc. They can’t work.
source
share