logoalt Hacker News

thechaoyesterday at 9:42 PM3 repliesview on HN

I know this is a bit cursed; but, I always wanted a bitfield-on-steroids construct:

    struct Dang : bits 64    // 64 bits wide, int total
    {
        foo : bits 5 @ 0;    // 5 bits wide at bit offset 0
        bar : bits 5 @ 0;
        baz : bits 16 @ 4;   // 16 bits wide at bit offset 4
        tom : bits 11 @ 32;
    };

Replies

Lvl999Noobyesterday at 10:33 PM

Are you saying you want foo and bar to completely overlap? And baz and foo / bar to partially overlap? And have lots of unused bits in there too?

sestepyesterday at 10:23 PM

I think you can do this with Virgil, but I'm having trouble finding the exact doc page at the moment: https://github.com/titzer/virgil

_bohmyesterday at 9:58 PM

You can kinda do this with Zig’s packed structs and arbitrary-width integers

show 1 reply