Re: execute a different function before main()
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Tue, 11 Mar 2008 12:34:55 -0400
aarklon@xxxxxxxxx wrote:
Hi all,
recently i read the following passage in a book
it is a compiler dependent thing if some feature is available that
allows you to execute some function before main() is called.
In turbo C compiler, there's one such fearture....the #pragma startup
directive.
I m giving an example of its use:-
#include<stdio.h>
void fun();
#pragma startup fun
int main()
{
printf("Arun");
}
void fun()
{
printf("Anand \n");
}
The o/p of the program given above will be :- Anand
my question is there a standard way in ANSI-C
to execute a different function before main() is called....??????
Yes. Two ways, in fact:
1) Run your program in a freestanding environment, where
"the name and type of the function called at program startup
are implementation-defined."
2) Use an editor to change the name of your existing
main() to something else, and to change the name of your
desired startup function to main().
(Yes, this is somewhat tongue in cheek. But there's a
serious point behind it: If you can modify the program source,
you are in control of what main() does. You can therefore
make it do whatever you wanted this other, magical function
to do -- so you don't need any magic.)
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: execute a different function before main()
- From: aarklon
- Re: execute a different function before main()
- References:
- execute a different function before main()
- From: aarklon
- execute a different function before main()
- Prev by Date: Re: execute a different function before main()
- Next by Date: Getting function signature
- Previous by thread: Re: execute a different function before main()
- Next by thread: Re: execute a different function before main()
- Index(es):
Relevant Pages
|
|