Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Implement bit fields #12
The next big thing that LLJS Structs currently lack compared to C∕C++ are bit fields. A syntax similar to this snippet would be great:
The static analysis should make sure that the sum of all consecutive bitfields is a multiple of 8.
I'm not sure though how to handle endianess.
Do you think that it is something that could be implemented?
This is possible, but what would the benefit of doing this in the language be, rather than implementing struct member functions that get and set the values into a byte field properly? Member functions are certainly more verbose, but I honestly don't know how often this comes up to know if that's a big deal. Haven't used bit fields before, personally. Do you need to do this a lot?
Basically, you feed binary data and a struct type to a parser with a API looking like this:
And you get the data of the buffer parsed to a
But there are complex, yet common cases such as bit fields or back references: