Consider the below program:
#pragma startup foo1
#pragma exit foo2
void foo1()
{
printf("Called before main\n");
}
void foo2()
{
printf("Called after main\n");
}
int main()
{
printf("main called\n");
return 0;
}
I am getting the output as: http://ideone.com/ooMFI
main called
Why the pragma is not working here?
Why foo1() & foo2() are not called?
Because none of these pragmas are recognized by GCC. In general, stay clear of pragmas if you’re trying to write portable code, because they differ per compiler and even per platform within the same compiler family.