Comment

Comment by lsof

The language I'm working on has the following syntax

  bitfield ColorWriteMaskFlags : u32 {
    red 1 bool,
    green 1 bool,
    blue 1 bool,
    alpha 1 bool,
  };
The number after the field name is the bit size. An (offset, size) pair can be used instead (offsets start at 0 when not explicit). After that can be nothing (the bit field is an unsigned number), or the word 'bool' (the bit field is a boolean) or the word 'signed' (the bit field is a signed number in two's complement). The raw value of the bitfield can always be accessed with 'foo.#raw'.

EDIT: There's also no restriction to how multiple fields can overlap, as long as they all fit within the backing type.

parent lsof 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton