AaronRobinsonMSFT / DNNE

Prototype native exports for a .NET Assembly.
MIT License
404 stars 41 forks source link

Using DNNE.C99Type for enum does compile under windows but not linux #188

Closed mkrmasch closed 6 months ago

mkrmasch commented 6 months ago

I currently do not have an idea why this works on windows but not in Linux.

If I defined a method parameter:

[UnmanagedCallersOnly]
 public static int FunctionCall([DNNE.C99Type("enum EnumTypeDefinition")] EnumTypeDefinition sparDefinition)

I defined the C99Type like this:

internal sealed class C99TypeAttribute : System.Attribute
{
    public C99TypeAttribute(string code) { }
}

it compiles with Windows but with Linux I get: error G13FECB51: variable has incomplete type 'enum EnumTypeDefinition'

A workaround would be not to use the type but integers of course but is a bit less readable

mkrmasch commented 6 months ago

ok, I think I found the problem. There was a missing declaration. still I wonder why windows allows that. `[DNNE.C99DeclCode(@"

include

enum EnumTypeDefinition
{
    item1,
   item2
};
")]`
AaronRobinsonMSFT commented 6 months ago

still I wonder why windows allows that.

The issue here is MSVC considers the type to be forward declared at this point. Dropping the enum gets the error you are looking for. This relates to MSVC and its tenuous adherence to C99.

https://godbolt.org/z/9bPbvqxz8