The following test case, when ran on Windows, results in the following code.
The output does not compile since it is missing an explicit cast from int to ulong.
Notably, the void* field is important for this edge case. Without it, the generator simply outputs 0.
[Test]
public Task RuntimeSizeofMacroTest()
{
var inputContents = """
typedef struct XrEventDataBuffer {
const void* next;
} XrEventDataBuffer;
#define XR_MAX_EVENT_DATA_SIZE sizeof(XrEventDataBuffer)
""";
return ValidateGeneratedCSharpLatestWindowsBaselineAsync(inputContents, PInvokeGeneratorConfigurationOptions.GenerateUnmanagedConstants);
}
namespace ClangSharp.Test
{
public unsafe partial struct XrEventDataBuffer
{
[NativeTypeName("const void *")]
public void* next;
}
public static unsafe partial class Methods
{
[NativeTypeName("#define XR_MAX_EVENT_DATA_SIZE sizeof(XrEventDataBuffer)")]
public static ulong XR_MAX_EVENT_DATA_SIZE => sizeof(XrEventDataBuffer);
}
}
The following test case, when ran on Windows, results in the following code.
The output does not compile since it is missing an explicit cast from int to ulong.
Notably, the
void*field is important for this edge case. Without it, the generator simply outputs 0.