Syntax:
#pragma startup [priority]
#pragma exit [priority]
Where priority is optional integral number.
For user priority varies from 64 to 255
For c libraries priority varies from 0 to 63
Default priority is 100.
pragma startup always execute the function before the main function pragma exit always execute the function after the main function.Function declaration of must be before startup and exit pragma directives and function must not take any argument and return void. If more than one startup directive then priority decides which will execute first.
startup:
Lower value: higher priority i.e. functions will execute first. If more than one exit directive then priority decides which will execute first.
exit:
Higher value: higher priority i.e. functions will execute first. For example
void india ();
void usa () ;
#pragma startup india 105
#pragma startup usa
#pragma exit usa
#pragma exit india 105
void main(){
printf("\nI am in main");
getch();
}
void india (){
printf("\nI am in india ");
getch();
}
void usa (){
printf("\nI am in usa ");
getch();
}
Output:
I am in usa
I am in India
I am in main
I am in India
I am in usa
Explanation:
Above program there are two startup directives which will execute before the main function.
Function name India has priority 105
Function name usa has priority 100 (default)
So usa function will execute first than India function and above program there are two exit directive which will execute after the main function.
Function name India has priority 105
Function name usa has priority 100 (default)
So india function will execute first than usa function.
- Preprocessor definitions in c
- Preprocessor directive in c
- #include directive in c
- # define directive in c
- Pragma directive in c
- #pragma startup and #pragma exit
- #pragma inline direcive
- Warning directive
- Preprocessor operators in c
- # if directive in c
- #line directive in c
- # error directive in c
- # elif in c
- # ifdef and #endif in c
- # ifndef in c example
- #undef in c
- What is header file in ?
- C preprocessor questions
- C tutorial home.
7 comments:
i m on this site for past 2 hours still not in hurry to leave it..to the point info..thumbs up..keep it up..i m sure evryone shuold be liking this site
Is awesome !!!!!!!!!
Realy like this site..
searching through google and came here. with it self in one program I like this way of explanation.
Thanks
you did good job. it is helpful for learner and who want to perfect in c.
i love this site. plz carry on your job and add more question with explanation. i am lover of your site.
you done good job :)
tnx.site is really helpfull keep it up !
very good explanation and clear understanding!!!
Post a Comment