Globals are evil. In your case, you can fight evil with even more evil.
Let's say your code is someting like this:
#include <iostream>
#include <cstdlib>
using namespace std;
X myGlobalX;
void FinalFunction(void)
{
}
int main()
{
atexit(FinalFunction);
}
(source:
http://www.cprogramming.com/fod/atexit.html[
^]).
You can add a global boolean flag, like this:
#include <iostream>
#include <cstdlib>
using namespace std;
X myGlobalX;
bool calledFromFinalFunction = false;
void FinalFunction(void)
{
calledFromFinalFunction = true;
}
int main()
{
atexit(FinalFunction);
}
I'm ashamed to even suggest this, but anyway, hope this helps.