Question

I have this program which consists of a loader and different statically linked modules. The entrypoint of the program goes into a loop which executes all the module initialization-routines. The function-pointers to these routines are stored in a constant array in the main.cpp file.

My problem is that everytime I want to add or remove one of the modules I have to modify the array. I feel like there should be a method of automating this process. Is there a way to let the preprocessor load and parse a text-file holding the function-names? Or can I append new entries to the constant array from another .cpp file? How do I generate this array at compile-time?

Thanks in advance!

Was it helpful?

Solution 2

For anyone who cares. I have actually solved my problem. Turns out that gcc has a feature called 'section' which lets you create static memory regions that can be extended multiple times during compile-time by just specifying a declaration with this attribute. This created memory region packs the inserted elements side by side zero terminated, which gives it the characteristics of an array sorta. The memory location, lets call our section "name", can be accessed by defining extern const char pointers named __start_name and __end_name. Thanks gcc. :-)

OTHER TIPS

If the list of modules is known in compile time, while do not simple list them in makefile?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top