This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

this is the problem

Now I will explain the problem OK.

I have to find a way of calling a function before main.

How can I do it? can i use a pointer?

Give all the possible solutions as soon as you can.

See you soon,

Necra

Parents
  • C++ can call constructors of global variables before the call to main().

    C will not call anything before main(), unless the function call is explicitly added somewhere in the startup file(s). Initialized global variables can only be initialized with _constant_ data. A function call is not constant data!

    Some compilers have special methods to specify functions to be called before main() - basically a way to create self-initializing lib files, where the link order of the library files controls the order the libraries gets initialized.

    But once again: EXACTLY WHY do you need to call a function before main()? The startup files fixes the stack. They initialize variables. They zero memory. They call required C RTL initialization functions.

Reply
  • C++ can call constructors of global variables before the call to main().

    C will not call anything before main(), unless the function call is explicitly added somewhere in the startup file(s). Initialized global variables can only be initialized with _constant_ data. A function call is not constant data!

    Some compilers have special methods to specify functions to be called before main() - basically a way to create self-initializing lib files, where the link order of the library files controls the order the libraries gets initialized.

    But once again: EXACTLY WHY do you need to call a function before main()? The startup files fixes the stack. They initialize variables. They zero memory. They call required C RTL initialization functions.

Children