may be it is a simple question, but it was coming up, when I read the in the title mentioned article.
The text says that to enable global objects, I need "int __cxa_atexit(void (* f)(void *), void *p, void *d);", which is right, because without the code it won't compile. There is the following Code in the Article, to implement this:
Code: Select all
extern "C"
{
int __cxa_atexit(void (*f)(void *), void *p, void *d);
void __cxa_finalize(void *d);
};
void *__dso_handle; /*only the address of this symbol is taken by gcc*/
struct object
{
void (*f)(void*);
void *p;
void *d;
} object[32] = {0};
unsigned int iObject = 0;
int __cxa_atexit(void (*f)(void *), void *p, void *d)
{
if (iObject >= 32) return -1;
object[iObject].f = f;
object[iObject].p = p;
object[iObject].d = d;
++iObject;
return 0;
}
/* This currently destroys all objects */
void __cxa_finalize(void *d)
{
unsigned int i = iObject;
for (; i > 0; --i)
{
--iObject;
object[iObject].f(object[iObject].p);
}
}
Is it, that it looks a bit prettier or why?
Cheers Christian