IL offers two statements for calling functions, i.e. call and callvirt. Call is used to call the non-virtual or static functions or any function where compiler doesn't want to do a null check on the reference.
callvirt is used to call virtual functions, non-virtual functions are also called, since compiler does a null check on the reference at run time.
Now while going through CLR via C# i found following example.
internal class SomeClass
{
public override String ToString()
{
return base.ToString();
}
}
Now ToString() is virtual function, but compiler generates the call instruction for it its ok.But the reason that Jeffrey mentioned that why callvirt is not generated because in that case the ToString() would be called recursively and will cause the StackOverFlow Exception, I tried to understand but was unable to wrap my mind around this idea ? Can anyone explain why it will cause a recursive call?
Thanks..