main function

Is it possible to execute any function before main() function in C or C++.

just a small doubt why you are looking for somthing like this.

as per my knowledge its not possible

after the entry pt of an exe it is the main function that is called first ( actually loaded into stack trace )

i am not sure of this,

if you want some other function to execute first
then you need to have your exe generator, with options to work at the entry pt level of any exe

The C standard says that a module called "_start" runs first, then calls main().
You can usually see it in the output from nm:

_sr4export          |      6968|extern|code   |$CODE$
_start              |          |undef |code   |
_start              |      6512|uext  |stub   |
_tepv               |1073746360|undef |common |$BSS$

You can create your own version of start if you want, then link against it.

Why you would want to do this... I don't know.

Shoot me if Im wrong, but wouldn't it just be easier to have main() call your function before anything else?

hi
this might be a way but on my machine(linux) it didnt worked
anyway try it out
use

#pragma start
some_function()
{
printf("hi\n");
}

main()
{
printf("hello\n");
}

ideally it should give the output as
hi
hello

#pragma startup f_start
#pragma exit f_exit

f_start()
{
printf("hi\n");
}

f_exit()
{
printf("EXIT\n");
}

main()
{
printf("hello\n");
}

----O/P---

Hi
hello
EXIT

----
make sure that f_start and f_exit should not have any input and output arguments.