Why Nostr? What is Njump?
2025-03-26 21:53:25

Kate on Nostr: should C enums with less than < (sizeof enum int type in bits) entries just be ...

should C enums with less than < (sizeof enum int type in bits) entries just be bitflags instead of seperate values?

i think it makes a lot of sense from a optimization perspective.

think of
enum Something {
A = 0,
B,
C,
D,
E,
..
};

If you now want to check if s of type Something is either A, C, D or E, you end up with 3 comparisons.

whereas representing it as bitflags, you could just do like (1 << A) | (1 << C) | (1 << D) | (1 << E) at compiletime, perform a single bitwise AND, and you're done?
Author Public Key
npub1wjul7k4nh56tal746f5cjd380xskshqk443d43nef4yd0pw3kn2s7dp88l