//=========== Visual C++ version ===============
#include <stdio.h>
int foo1()
{
printf("%s\n", __FUNCTION__);
return 0;
}
int foo2()
{
printf("%s\n", __FUNCTION__);
return 0;
}
int foo3()
{
printf("%s\n", __FUNCTION__);
return 1;
}
int foo4()
{
printf("%s\n", __FUNCTION__);
return 1;
}
typedef int (FUNC)(void);
#pragma data_seg(".CRT$XIU")
static FUNC * before[] = { foo1, foo2 };
#pragma data_seg(".CRT$XPU")
static FUNC * after[] = { foo3, foo4 };
#pragma data_seg()
int main( int argc, char ** argv )
{
printf("%s\n", __FUNCTION__);
return 0;
}
//============ GCC version =======
#include <stdio.h>
__attribute((constructor)) void before_main()
{
printf("%s/n",__FUNCTION__);
}
__attribute((destructor)) void after_main()
{
printf("%s/n",__FUNCTION__);
}
int main( int argc, char ** argv )
{
printf("%s/n",__FUNCTION__);
return 0;
}