Is main() really start of a C++ program?

You are reading the sentence incorrectly.

A program shall contain a global function called main, which is the designated start of the program.

The standard is DEFINING the word “start” for the purposes of the remainder of the standard. It doesn’t say that no code executes before main is called. It says that the start of the program is considered to be at the function main.

Your program is compliant. Your program hasn’t “started” until main is started. The function is called before your program “starts” according to the definition of “start” in the standard, but that hardly matters. A LOT of code is executed before main is ever called in every program, not just this example.

For the purposes of discussion, your function is executed prior to the ‘start’ of the program, and that is fully compliant with the standard.

Leave a Comment