/*This Program demonstrates the use of #pragma directive. #pragma startup can be used to call a function before main.The function must not returning anything other than void and must not contain any arguments. Syntax : #pragma startup function-name [priority] Here function-name is the name of a function and priority is optional. priority can be from 64 to 255.Do not use priority from 0 to 63 because they are used by C libraries. 100 is a Default priority 255 is a lowest priority Developed on :- 28/03/2009 Developed by :- Malhar Vora Email :- vbmade2000@gmail.com WebSite :- http://malhar2010.blogspot.com Development Status :- Completed ******************************************************************/ #includevoid PrintChar1() { printf("Hello before main1\n"); } void PrintChar2() { printf("Hello before main2\n"); } #pragma startup PrintChar1 64 #pragma startup PrintChar2 65 void main() { printf("Hello from Main"); }
Saturday, August 21, 2010
Execute function before execution of main() function in C using #pragma directive
Labels:
C
Subscribe to:
Post Comments (Atom)
i executed but i doesnt... the output i got is Hello from Main
ReplyDeleteI think this doesn't work...
ReplyDeleteIt doesnt work...please update your post and say if this is possible in c?
ReplyDeleteThis comment has been removed by the author.
DeleteThis comment has been removed by the author.
Delete#include
ReplyDelete#include
void function();
#pragma startup function
void main()
{
printf("\n\tThis message is from main");
getch();
}
void function()
{
clrscr();
printf("\n\tThis message is from function before executing main");
}
Hope this program helps you..in this program function executes before executing main...just run it & you will understand..-Debayan Basu
#include
Delete#include
sorry for this error