Answer the question
In order to leave comments, you need to log in
What does Richter (CLR Via C#) mean in chapter 6?
Help me figure out what you mean.
In the 6th chapter about calling virtual methods, properties - Richter writes that the compiler uses two methods:
call and callvirt .
The latter is different in that it has a null check on the instance on which it is called. Also, callvirt is used, among other things, to call ordinary, instance, non-virtual methods.
And then - he writes - that sometimes, the compiler can use the call method to call virtual (!) Methods, and as an example, he gives the base.ToString () call. He explains this by saying that if callvirt were used when calling this method, then recursion and stack overflow would occur.
The question is why should it occur? And because of what?
Answer the question
In order to leave comments, you need to log in
Well, apparently, because the signature of the base.ToString() method is already in the virtual function table, and it would call itself when calling this method, because in the code that calls base.ToString(), it is already obvious that the signature the call matches the signature of the base class (the ToString() method is overridden), then there would be a call to the callvirt child class method, that is, the executable overloaded method in the child class, and it would call itself, instead of simply calling call without looking up the table signatures of virtual methods (overridden).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question