Closed ghost closed 6 years ago
Have you seen this issue: #11? It proposes byte offsets rather than bit ones. I had considered bit support, but hardware-wise it doesn't make much sense and would be kind of niche. Not against the idea though since even my example code is a bitfield based writer/reader that could benefit from such syntax. Would that or a variant work here?
Would this proposed syntax work with arrays of bitfields like if "a" in your example was an array of 2 elements?
Also just to be clear if you had say an uint8 with the value 255 the value in a and b would be 15 in your example?
An example I've seen before in networking. Using your syntax:
[left: uint8(1), right: uint8(1), up: uint8(1), down: uint8(1)]
Would this syntax be valid or is the user expected to define the full 8 bit mapping? Also is assuming LSB alignment ideal? Thus would someone be expected to do:
[left: uint8(1), right: uint8(1), up: uint8(1), down: uint8(1), padding: uint8(4)]
To get MSB alignment?
I'm closing this because I honestly can't see it being useful. Even in C it's hardly ever used, but is seen more as something that might be useful. In C the ordering of fields aren't defined allowing the compiler to optimize things. This is viewed as a benefit and annoyance. It brings up too many design choices to consider it here.
Hello, I also want propose bitfields in arrays, and structures. I early proposed with typed objects ES7, but I rephrase for ES types.
Array type:
typedef bitfieldArray [a: uint8(4), b: uint8(4) ]
When destructuring:
let [a: uint8, b: uint8] = typecast<bitfieldArray>(uint8variable);
let biffy = typecast<bitfieldArray>(uint8variable); // or just use typed with bitfield
Will presented as two uint8, which extracted bits.
When structuring.
let variable: uint8[] = typecast<uint8[]>(anotherBiffy);
Will converted as one bitfield.