diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index c73f6439..208411e6 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -126,8 +126,10 @@ namespace CppSharp.Generators.CSharp array.SizeType == ArrayType.ArraySize.Constant) { Type arrayType = array.Type.Desugar(); + PrimitiveType primitiveType; - if (arrayType.IsPointerToPrimitiveType(out primitiveType)) + if (arrayType.IsPointerToPrimitiveType(out primitiveType) && + !(arrayType is FunctionType)) { if (primitiveType == PrimitiveType.Void) { @@ -146,11 +148,18 @@ namespace CppSharp.Generators.CSharp }; } + var arrayElemType = array.Type.Visit(this, quals).ToString(); + + // C# does not support fixed arrays of machine pointer type (void* or IntPtr). + // In that case, replace it by a pointer to an integer type of the same size. + if (arrayElemType == IntPtrType) + arrayElemType = driver.TargetInfo.PointerWidth == 64 ? "long" : "int"; + // Do not write the fixed keyword multiple times for nested array types var fixedKeyword = array.Type is ArrayType ? string.Empty : "fixed "; return new CSharpTypePrinterResult() { - Type = string.Format("{0}{1}", fixedKeyword, array.Type.Visit(this, quals)), + Type = string.Format("{0}{1}", fixedKeyword, arrayElemType), NameSuffix = string.Format("[{0}]", array.Size) }; } diff --git a/tests/Common/Common.h b/tests/Common/Common.h index a68a718b..d1bdcb68 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -617,6 +617,17 @@ LPCWSTR TestWideStrings::GetWideNullPointer() { return 0; } enum struct MyEnum { A, B, C }; +typedef void (*VoidPtrRetFunctionTypedef) (); + +class DLL_API TestFixedArrays +{ +public: + TestFixedArrays(); + VoidPtrRetFunctionTypedef Array[10]; +}; + +TestFixedArrays::TestFixedArrays() {} + class DLL_API TestArraysPointers { public: