r/C_Programming • u/Yha_Boiii • Jul 07 '26
If statement checking a bool array?
Hi,
I need a custom sized bit vector so uint8_t won't suffice so the idea was to just initiate a bool array with size so then say i want to compare it. Ex**. the bool array is 6 bits and tried with `if (bool_var = 011001) { // do something}`, i suspect it comes just compares to an int given it compiles and wont run. Any idea on how to make it work?**
0
Upvotes
View all comments
Show parent comment
2
u/QuraToop314 Jul 08 '26
Well, 6 booleans are a waste – even if a boolean is only 1 byte in size, which is the minimum size of a type, with 6/7 states you’ve got 6/7 times 8 bits, which means you’re looking at 48 or 56 bytes, whereas with 6 or 7 bits you’d be at 1 byte for the same information. So I don’t know what you’re on about – those 2 bits aren’t a waste, as 1 byte is the minimum addressable size.