Q: How to call a function without calling inside main() function in C/C++ ?
A:
#pragma startup
#pragma exit
These two pragmas allow the program to specify function(s) that should becalled either:
■ upon program startup--before main() is called,
or
■ upon program exit--just before the program terminates through _exit
■Function must be declared or defined before the #pragma line reached.
Example:
#include
void f(void);
#pragma startup f
void main()
{}
void f()
{
printf("i'm called before main()...");
}
Happy Programming!
Tuesday, December 11, 2007
C/C++ Tips
Posted by
FrancisMichael
at
11:16 AM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment