Function Pointer
Function pointer can only be created by referencing a static method.
Function pointer can not be dereferenced.
Reference
See: Function pointers
Declaration
cs
delegate*<void> f = &M;
delegate*<int, void> g = &N;
static void M() { }
static void N(int a) { }
1
2
3
4
2
3
4
Invocation
A function pointer is a pure reference to the function without the delegate wrapper. There's no member of it to be accessed using .
, can only be invoked by ()
;
cs
delegate*<void> f = &M;
delegate*<int, void> g = &N;
f(); g(default);
static void M() { }
static void N(int a) { }
1
2
3
4
5
2
3
4
5
Type parameter variant
cs
delegate*<int, int, int> h = &O;
delegate*<char*, int*, int*> i = &P;
static int O(int a, int b) => default;
static unsafe int* P(void* m, int* b) => default;
1
2
3
4
2
3
4
Operator
cs
1
Calling Conventions
managed
managed
is the default calling convention of a function pointer.
cs
delegate*<void> f = &M;
delegate* managed<void> g = &M;
static void M() { }
1
2
3
2
3
unmanaged
Cdecl
Stdcall
Fastcall
Thiscall
Default
unmanaged
calling convention
The default unmanaged
calling convention is left to CLR to make the decision.
cs
public unsafe static void M<T>(delegate* unmanaged<T> f) { }
1
Type Checking
Type checking of two function pointer includes function signatures and their calling convention.
cs
delegate*<void> f = &M;
delegate* managed<void> g = &N;
delegate* unmanaged<void> h = ...;
f = g;
g = h; // calling convention not matched!
static void M() { }
static void N() { }
1
2
3
4
5
6
7
2
3
4
5
6
7