Search code examples
c++cfunctionprogram-entry-point

how to start the execution of a program in c/c++ from a different function,but not main()


Possible Duplicate:
Does the program execution always start from main in C?

i want to start the execution of my program which contains 2 functions (excluding main)

void check(void)
void execute(void)

i want to start my execution from check(), is it possible in c/c++?


Solution

  • I have found solution to my own question. we can simply use

    #pragma startup function-name <priority>
    #pragma exit function-name <priority>
    

    These two pragmas allow the program to specify function(s) that should be called either upon program startup (before the main function is called), or program exit (just before the program terminates through _exit).

    The specified function-name must be a previously declared function taking no arguments and returning void; in other words, it should be declared as:

    void func(void);
    

    The optional priority parameter should be an integer in the range 64 to 255. The highest priority is 0. Functions with higher priorities are called first at startup and last at exit. If you don't specify a priority, it defaults to 100. thanks!