Automatic Casting in IL

Published July 15, 2011
Advertisement
While developing spectral, I discovered something peculiar.

Consider this sample pseudo C#/IL:

public static T Sqrt(T value)
{
ldarg.0
conv.r8
call double System.Math.Sqrt(double)
ret
}

You'd expect some sort of error, right? The return type is T, but the returned value is a double.
Turns out it runs fine. What's more, you don't even need the conv.r8 instruction.

I have to say, IL's flexibility is amazing.

YellPika
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement