I am trying to understand the meaning of the saying "Function calls are resolved at compiled time". I know about the concept of polymorphism and there i know that virtual
functions are called(or resolve or whichever is the correct phrase i don't know the difference if any) at runtime.
I want to know what does it mean to say "compile time" or "runtime" in this(function call) context.
Below is an example and explanation of my current unerstanding which most probably is wrong.
const int n = 10; //STATEMENT 1
void func(int x)
{
//..
}
int main()
{
int p = 0; //this is dynamic initialization.
func(p);//STATEMENT 2
}
To my current understanding,
- In statement 1,
n
is a constant expression and is known at compile time. So the compiler might replace all occurrences ofn
with10
. But it(compiler) is not required to do(replace all occurences) so. Is my explanation of this statement correct? - I used to think that
p
is passed at runtime(whatever that means) but then i read someone say that all function calls are resolved at compile time. And i got confused. So i am not sure if this function is called/resolved at runtime or compile time. I think the reason i got confused is because
a) I don't know the fundamental difference between compile time and runtime
b) I don't know the difference between the phrase function is "resolved" and
p
is passed at "runtime".
So can someone clear these concepts and provide necessary links so that i can learn more about them.
- dynamic initialization happens at runtime and static initialization happens at compile time.
- compile time means hardcoded/embedded into the executable. But then when i wrote
int p = 0;
which is dynamic initialization and happens at runtime. But where does the integer literal0
comes from so that it can be used to initialize the variablep
at runtime. Was0
also hardcoded into the binary and if so then why can't this statement happen(that isp
can be statically initialized) at compile time.
The question might be too broad so i will appreciate(upvote) if anyone can answer any of the question.