[Mono-list] Base class casting weirdness

Mark Hurley debian4tux@telocity.com
Sat, 19 Jan 2002 20:51:51 -0500


On Fri, Jan 18, 2002 at 05:39:06AM +1000, Dominic Cooney wrote:
> > CSC will compile it, but you'll get a StackOverflowException at 
> > runtime. Why would I want to write it this way instead of using 
> > 'base'? Well, I've got a class C derived from B, that wants to 
> > implement Foo by invoking A's definition. Can anyone think of a way to
> 
> > do this? Is the runtime exception correct, or is this an SDK bug? And 
> > what does MCS/Mono do with this?
> 
> Mark,
> 
> In terms of your problem (invoking A::Foo for C::Foo) you can hack the
> IL so the body of C::Foo is:
> 
> 	ldarg.0
> 	tail.call string A::Foo()

Very good...I didn't catch that prefix instruction last night.  I got 
all wrapped up in exactly what was happening with the vtable.  Did I 
mention I love tearing and learning this stuff! ;)

One question (opinion-based) I'm assuming use of the prefix [tail] 
wouldn't be considered a hack in this instance? Do you have any design 
examples using the [tail.] instruction? I did read up on it and 
understand it's purpose...but would this be useful only in recursive 
functions?

Thanks...

Mark Hurley

For those who find us years later...Google eyes:  [tail.] definition:

Prefix instruction, following call terminates method.