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?
Published at
2025-03-26 21:53:25Event JSON
{
"id": "7930513efaf1574476a62044fb519f38c8bd9335608d5042a69233b791235f46",
"pubkey": "74b9ff5ab3bd34beffd5d26989362779a1685c16ad62dac6794d48d785d1b4d5",
"created_at": 1743026005,
"kind": 1,
"tags": [
[
"proxy",
"https://comp.lain.la/objects/44993ca3-0c98-4ced-8c35-28ffe2f8e247",
"activitypub"
]
],
"content": "should C enums with less than \u003c (sizeof enum int type in bits) entries just be bitflags instead of seperate values?\n\ni think it makes a lot of sense from a optimization perspective.\n\nthink of\nenum Something {\n A = 0,\n B,\n C,\n D,\n E,\n..\n};\n\nIf you now want to check if s of type Something is either A, C, D or E, you end up with 3 comparisons.\n\nwhereas representing it as bitflags, you could just do like (1 \u003c\u003c A) | (1 \u003c\u003c C) | (1 \u003c\u003c D) | (1 \u003c\u003c E) at compiletime, perform a single bitwise AND, and you're done?",
"sig": "ccc668bd160a8644b9fbfd3efc737c010c76b7e7d623730dca668faeb26709c3b88fa5dba5261ac89cfef95490c8851a28faa50841e22c8cdb990e9a3e6a01f5"
}