Address of function main() in C/C++

后端 未结 3 1411
一生所求
一生所求 2021-01-06 00:33

Is there a way to find out the address of main() in C or C++ ? Since it is itself a function ,would there be an address of it own ?

3条回答
  •  清歌不尽
    2021-01-06 00:59

    If for any system you can't find the address of main.. put an invocation to a function foo() as the only statement in main, have main return whatever it returns and use the address of foo rather than main.

    Note that calling main won't necessarily restart your code, even if there are no static/global variables. The compiler generates start up code before actually calling main.

    If you want to breakpoint before this call to main write something like:

    static int i=foo();
    

    and foo will be called during the earlier data initialisation step.

提交回复
热议问题