1.8 KiB
C# Language Design Meeting for Jan 23, 2019
Agenda
Function pointers (Updated proposal)
Discussion
Creation of a function pointer to a managed method
The proposal is &Class.Method
to produce a function pointer. The question
is whether &Class.Method
is target-typed, whether it has a natural type
when there's only one member in the method group, or both.
Target-typing is useful because, like with delegates, it allows you to select a unique method out of a method group with multiple incompatible overloads.
Natural type is useful because it allows things like var
and void*
.
Conclusion
Let's start by only doing target-typing. Also, the section "better function member" is not necessary without the natural typing.
DllImport CallingConvention?
There is actually a stub that the compiler calls for P/Invoke with DllImport that is always done using the managed calling convention, so there's no reason for function pointers to use the DllImportAttribute.
NativeCallback is intended for the scenario where you want to avoid the stub overhead.
NativeCallableAttribute
Let's look at this in more detail.
Syntax
1. func* managed int(string)
2. func*(string)->int
3. func* managed (string)->int
4. func* managed (string)=>int
5. managed int(string)*
5a. int(string)*
6. managed int(string)
7. managed (string)->int
8. delegate* int(string)
9. func int(string)*
10. delegate int(string)*
Conclusion
We're not sure about all the potential ambiguities here. Let's look at (5a), possibly disambiguating with the calling convention.
Things to clarify in spec
- What does the CLR do if you try to call a method that has a modreq/modopt in
the signature, but the
calli
has the signature without the modreq/modopt?