C lang Bit fields described by MemoryLayout in Java

54 views Asked by At

How can a C language struct using Bit fields be described using Java MemoryLayout API (part of JEP 442: Foreign Function & Memory API (Third Preview))?

For example how to describe C struct declaration

struct {
    unsigned int first;
    unsigned int second: 2;
    unsigned int third: 3;
};

?

When ignoring the bit fields it would be something like

MemoryLayout.structLayout(
        ValueLayout.JAVA_INT.withName("first"),
        ValueLayout.JAVA_INT.withName("second"),
        ValueLayout.JAVA_INT.withName("third")
);
0

There are 0 answers