[Proposal] Better interop between function ptr and delegates #3680
Replies: 2 comments 5 replies
-
ethereum_book/code/OpenZeppelin/contracts/SampleCrowdsale.sol |
Beta Was this translation helpful? Give feedback.
-
@sakno, you might consider rewording this so that it proposes C# stop hiding the existing delegate constructor which takes a function pointer. That is, every delegate currently generated exposes the following (noting that the actual language spec may have slightly different rules here, this is what the compiler emits today for CIL and that some TFMs may be lacking
The first method (the constructor) takes the |
Beta Was this translation helpful? Give feedback.
-
Motivation
C# 9 introduces a syntax for obtaining function pointers. But original PR nothing says about interop with regular delegate types and possibility to create delegate instance from function pointer.
Goals
Non-Goals
ExplicitThis
managed calling convention by function pointer syntaxProposal
C# compiler may allow to pass function pointer as an argument of delegate constructor:
The type of the argument should be a typed function pointer. Type
void*
is not allowed. Additionally, the compiler can control the calling convention at compile time:UnmanagedFunctionPointerAttribute
attribute with appropriate calling convention.Closed delegate can be created from pointer to managed function only. Implicit first argument can be passed as the second argument of delegate constructor:
Alternatives
Marshal.GetDelegateForFunctionPointer method can be improved to allow generic delegates. However, such approach allows to use incorrect calling convention.
Beta Was this translation helpful? Give feedback.
All reactions