The CPP program crash before the breakpoint. Why?

topic description

A CPP program that breaks the first line of the main function when debugging. After run, it will crash before it reaches the breakpoint.
what is the possible cause of this problem?

sources of topics and their own ideas

this is a question I encountered when I interviewed Jinri Toutiao Shanghai. I had no idea at all.

the boss taught me

CPP
Jul.07,2022

since there is no run in the first line of main , I wonder if there was an error before the first line? For example, in the following code, if you break the cout breakpoint on the first line of main , you will crash before the breakpoint, because the constructor of the global variable is executed before the mian function. I thought about it briefly, and this is also a reason. There should be some other reasons. Let's see what other great gods say.

main CPP

__attribute__((constructor)) void doBeforeMain(){
    printf(" : %s \n",__func__);
}
Menu