When does early binding happen?

Thing 1:

Static binding takes place during compilation - function calls are replaced with an instruction saying "go here for the appropriate function definition".

--

Thing 2:

The typical phases of compilation are:

1. Lexical analysis (scanning)
2. Syntax analysis (parsing)
3. Semantic analysis
4. Intermediate code generation
5. Optimization
6. Code generation

--

During which phase of compilation does static binding occur?
I guess this is what's called "devirtualization" which GCC has optimization flags for ...
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fdevirtualize
... so it's probably done in the optimization phase.

Update: That is for virtual functions. For non-virtual functions it should be known which function to call already after overload resolution ...
https://en.cppreference.com/w/cpp/language/overload_resolution
... which I guess is part of the "semantic analysis" phase.
Last edited on
Registered users can post here. Sign in or register to post.