0

How should I interpret FNPTR followed by a MethodDefSig or by a MethodRefSig? I mean that BOOLEAN is bool, OBJECT is object, SZARRAY is a zero-based array, but FNPTR have a method signature and I can't write something like:

public static int*(int) myFunction();

Can anyone explain to me how it works?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
tairqammar
  • 151
  • 3
  • 10

1 Answers1

1

FNPTR is a signature element denoting a low-level pointer to a managed function which can be used by the calli opcode, for example. As far as I know, only C++/CLI has a use for them (to support standard C++ function pointers and references), and I suppose low-level languages were the reason they were included in CIL in the first place.

Despite being a core feature of CLI, there is zero support for them in the reflection API (apart from this thing). They have no actual use apart from creating a distinct signature for method overloads, so you can safely use IntPtr if you are able to.

Function pointers are basically a low-level equivalent of delegates, only without the target object (and not being objects themselves). If you need a high-level equivalent, Action and Func delegates might be sufficient.

IS4
  • 11,945
  • 2
  • 47
  • 86
  • I should also mention that my library, [SharpUtils](https://github.com/IllidanS4/SharpUtils), contains a variety of helper methods for signatures, as well as a type system extension supporting function pointer types. – IS4 Jul 20 '18 at 19:33