ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

Unions inside functions aren't handled correctly

Open WhiteBlackGoose opened this issue 3 years ago • 1 comments

C code:

extFloat80_t extF80_add( extFloat80_t a, extFloat80_t b )
{
    union { struct extFloat80M s; extFloat80_t f; } uA;
...

The generated C# code:

[return: NativeTypeName("extFloat80_t")]
public static extFloat80M extF80_add([NativeTypeName("extFloat80_t")] extFloat80M a, [NativeTypeName("extFloat80_t")] extFloat80M b)
{

    [StructLayout(LayoutKind.Explicit)]
    public partial struct __AnonymousRecord_extF80_add_L47_C5
    {
        [FieldOffset(0)]
        [NativeTypeName("struct extFloat80M")]
        public extFloat80M s;

        [FieldOffset(0)]
        [NativeTypeName("extFloat80_t")]
        public extFloat80M f;
    }
, uA = new __AnonymousRecord_extF80_add_L47_C5()
...

WhiteBlackGoose avatar Sep 27 '21 18:09 WhiteBlackGoose

This is one that isn't really "easy" to handle.

There is no corresponding concept for defining a struct inside a function in C#/.NET and so it must be "hoisted" out instead. This risks conflicts and other issues, so its not something that's trivial to handle.

tannergooding avatar Sep 18 '22 19:09 tannergooding