8000 Support bit fields in structs · Issue #665 · nasa/fpp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Support bit fields in structs #665
Open
@bocchino

Description

@bocchino

Struct bit fields are useful for expressing serialized data formats that use bit packing. We would need to devise a syntax for this. The C and C++ way is to specify a type that is larger than the bit field, and then qualify the type with the smaller size, like this:

struct S {
  I32 a : 4 // a is a 4-bit signed field
  U32 b : 4 // b is a 4-bit unsigned field
}

This seems awkward. The only purpose of writing I32 seems to be to specify the I part; you could have written I8 or I16 or I64 there, and the meaning would be the same. It seems to me it would be more natural to directly specify the signedness and the bit width, like this:

struct {
  a: signed 4
  b: unsigned 4
}

One question is whether the bit packing would control the in-memory representation, or just the serialized form. If it controls the in-memory representation, then how do we implement the bit packing? Using C++ bit packing? Or by code-generating the bit shifts? If it doesn't control the in-memory representation, then the implementation could choose a primitive integer type to hold each bit string. For example, the struct above could be implemented with a pair of U8 fields. That could be more efficient for some operations, but it would waste memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    CCB

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0