The following IL code creates a Type instance named (fnptr)*
(token 0x2000000 - invalid, module mscorlib.dll).
ldtoken method void* ()*
call cla
Not sure where you're seeing the FNPTR being declared.
For this code:
.assembly extern mscorlib {}
.assembly Test
{
.ver 1:0:1:0
}
.module test.exe
.method static void main() cil managed
{
.maxstack 1
.entrypoint
ldtoken method void* ()*
call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
ldtoken method void* ()
call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
ret
}
ILASM (4.5.22.0) outputs the following:
.method privatescope static void main$PST06000001() cil managed
{
.entrypoint
// Code size 21 (0x15)
.maxstack 1
IL_0000: ldtoken method void *()*
IL_0005: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_000a: ldtoken method void *()
IL_000f: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0014: ret
} // end of method 'Global Functions'::main
Perhaps I am being dense here, but I am not seeing FNPTR being generated from this code:
typeof(StringBuilder).ToString();
The IL looks like this:
IL_0000: nop
IL_0001: ldtoken [mscorlib]System.Text.StringBuilder
IL_0006: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_000b: callvirt instance string [mscorlib]System.Object::ToString()
IL_0010: pop
IL_0011: ret
The Type.ToString()
call is a callvirt
operation since ToString() is a virtual method.
Virtual functions are usually manifested as structs of function pointers which would, I guess, result in a FNPTR being emitted. If you omit the *
in ()*
resulting in ()
, you're now describing a function, not a function pointer.
What version of .NET are you using when you see the FNPTR? What are you using to extract the IL?