What happens before main in C++?

前端 未结 3 1081
梦谈多话
梦谈多话 2020-12-06 07:34

I know in C, before application can get started in main(), some entity must:

  1. Initialize Global variables
  2. Set the stack pointer to the lo
3条回答
  •  长情又很酷
    2020-12-06 08:03

    In this answer I have investigated the entry point location for a C program: Is main() really start of a C++ program?

    When I do an analogous analysis for C++, the results are basically the same, and as others mentioned, it is part of glibc with backtrace at main:

    #0  main () at hello.cpp:3
    #1  0x00007ffff7be50b3 in __libc_start_main (main=0x5555555551a9 , argc=1, argv=0x7fffffffbfb8, init=, fini=, rtld_fini=, stack_end=0x7fffffffbfa8) at ../csu/libc-start.c:308
    #2  0x00005555555550ee in _start ()
    

    so the exact same line as that of a C program.

    I think the C++ compiler is just calling into hooks to achieve any C++ specific functionality, and things are pretty well factored across C/C++.

提交回复
热议问题