We can execute any member function or any other execution before main() function by using:
"#pragma startup".Syntax: #pragma startup [priority]//without semicolon
Example:
#includeclass CL{public: //A constructor CL(){ cout <> "
The object is creating"; } //A member function void obj_func() { cout <> "
This is a function of object"; }};void func_before_main (); //function declaration#pragma startup func_before_main 65 //setting a function to execute beforemain()void main (){ cout <&;t; "
This is main() ";}// A function definationvoid func_before_main() { cout << "
This is func_before_main() "; CL obj1; //creating an object, and calling its constructor obj1.obj_func(); //calling a member function of an object}
In defining such functions, the functions should not carry any attributenor return any value. It should be defined before #pragma statement.
Priority is optional. It is ranging from 64 to 100 (recomended).
0-------Highest priority used by C Libraries
63------Lowest priority used by C Libraries
64------First available Priority
100-----Default priority
255-----Lowest priority.