ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

Struct initialization in global variable emits invalid C#

Open jwosty opened this issue 2 years ago • 0 comments

C header:

typedef struct Point
{
    int x;
    int y;
} Point;

Point MyGlobalPoint = { .x = 10, .y = 20 };

produces these C# bindings (missing the end curly brace on MyGlobalPoint):

namespace LibFoo.Interop
{
    public partial struct Point
    {
        public int x;

        public int y;
    }

    public static partial class NativeMethods
    {
        [NativeTypeName("struct Point")]
        public static Point MyGlobalPoint = new Point
        {
            x = 10,
            y = 20,
    }
}

It works fine for const struct Point MyConstPoint = { .x = 10, .y = 20 };

jwosty avatar Nov 30 '23 20:11 jwosty