cm0002@lemmy.world to Programmer Humor@programming.dev · 8 days agoTell me the truth ...piefed.jeena.netexternal-linkmessage-square150fedilinkarrow-up11arrow-down10
arrow-up11arrow-down1external-linkTell me the truth ...piefed.jeena.netcm0002@lemmy.world to Programmer Humor@programming.dev · 8 days agomessage-square150fedilink
minus-squareh4x0r@lemmy.dbzer0.comlinkfedilinkEnglisharrow-up0·8 days agoThis was gonna be my response to OP so I’ll offer an alternative approach instead: typedef enum flags_e : unsigned char { F_1 = (1 << 0), F_2 = (1 << 1), F_3 = (1 << 2), F_4 = (1 << 3), F_5 = (1 << 4), F_6 = (1 << 5), F_7 = (1 << 6), F_8 = (1 << 7), } Flags; int main(void) { Flags f = F_1 | F_3 | F_5; if (f & F_1 && f & F_3) { // do F_1 and F_3 stuff } }
This was gonna be my response to OP so I’ll offer an alternative approach instead:
typedef enum flags_e : unsigned char { F_1 = (1 << 0), F_2 = (1 << 1), F_3 = (1 << 2), F_4 = (1 << 3), F_5 = (1 << 4), F_6 = (1 << 5), F_7 = (1 << 6), F_8 = (1 << 7), } Flags; int main(void) { Flags f = F_1 | F_3 | F_5; if (f & F_1 && f & F_3) { // do F_1 and F_3 stuff } }