This is a question that was asked in the interview and answered yes. The first feeling of the answer is no, for a moment did not think out the reason can only answer is. At that time was too tense, in fact, recall the assembly language should think of the program's entry address can be specified, C language compiler defaults to main as the entry address.
After the online lookup, found the __attribute__ this keyword, it can set function properties, variable properties, type properties.
Reference: http://www.cnblogs.com/Anker/p/3462363.html
Look at the following example:
gcc compiler
#include <stdio.h>
__attribute__ ((constructor)) void Before_main ()
{
printf ("%s\n" , __function__);
}
__attribute__ ((destructor)) void After_main ()
{
printf ("%s\n", __function__);
}
int main ()
{
printf ("%s\n", __function__);
return 0;
}
You can see that the above program does not start with the main function. The constructor setting is performed before Main, and the destructor setting is performed after main.