c2cs
c2cs copied to clipboard
Function parameter decay
It is possible to typedef a function
#include <stdio.h>
#include "ffi_helper.h"
typedef void Handler(unsigned int);
typedef void (*Handler2)(unsigned int);
FFI_API_DECL void function_pointer_decay(Handler* handler)
{
}
FFI_API_DECL void function_pointer_decay2(Handler handler)
{
}
FFI_API_DECL void function_pointer_regular(Handler2 handler)
{
}
where those three functions have identical signature, but get generated with different signatures on C# side
private const string LibraryName = "test_class";
[LibraryImport(LibraryName, EntryPoint = "function_pointer_decay")]
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
public static partial void function_pointer_decay(Handler* handler);
[LibraryImport(LibraryName, EntryPoint = "function_pointer_decay2")]
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
public static partial void function_pointer_decay2(Handler handler);
[LibraryImport(LibraryName, EntryPoint = "function_pointer_regular")]
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
public static partial void function_pointer_regular(Handler2 handler);
[StructLayout(LayoutKind.Sequential)]
public partial struct Handler
{
public delegate* unmanaged[Cdecl]<uint, void> Pointer;
public Handler(delegate* unmanaged[Cdecl]<uint, void> pointer)
{
Pointer = pointer;
}
}
[StructLayout(LayoutKind.Sequential)]
public partial struct Handler2
{
public delegate* unmanaged[Cdecl]<uint, void> Pointer;
public Handler2(delegate* unmanaged[Cdecl]<uint, void> pointer)
{
Pointer = pointer;
}
}
}
(function_pointer_decay(Handler* handler); should be function_pointer_decay(Handler handler);)