I have three *.h files:
A.h:
<some types>
extern sometype1 somevar1;
B.h:
<some types>
extern sometype2 somevar2;
C.h:
<some types>
extern sometype3 somevar3;
And I have the D.c file:
#include "A.h"
#include "B.h"
#include "C.h"
int freethemall()
{
TheFunctionFromAhFileForFreeingTheSomevar1Resources();
TheFunctionFromBhFileForFreeingTheSomevar2Resources();
TheFunctionFromChFileForFreeingTheSomevar3Resources();
}
This project is some kind of framework.
Sometimes I don't need all the modules - A, B or C, for example, I will need only A and B modules. But the structure of my framework initialization is as follows:
#include "A.h"
#include "B.h"
<Frameworkname>Init();
<do some code here>
<Frameworkname>Free();
So, it's very very uncomfortable to call all the Free functions from every module instead of only one ...Free() function:
#include "A.h"
#include "B.h"
<Frameworkname>Init();
<do some code here>
<Frameworkname><modulename1>Free();
<Frameworkname><modulename2>Free();
..
<Frameworkname><modulenameN>Free();
In this case N is only 2, but I have about 20 modules, so It will be not programmer-friendly to count them all.
How can I change freethemall() function to call only destructor of modules that I used and included? Note, that D.h contains that function and there are a lot of modules that include D.h.
P.S. I can include D.h module in every other module if its needed.
As other way to solve it, I need a function that will be called before the module finalization as in last Delphi languages:
Unit ...
Finalization
Callme;
End.
There is no need to call it from freethemall(), but it's some kind of lead to solve this problem.
Thank you for any advice.