I need to store exactly four booleans in my struct in c. Yes I could use four integers or put them into an array but I would like to do it a bit nicer. I was thinking about an int like "0000" where each number would represent the boolean value, but then when editing I cant edit only the one digit, right? That doesnt look perfect either...
Thanks for any ideas
You could use a bitfield struct:
struct foo {
unsigned boolean1 : 1;
unsigned boolean2 : 1;
unsigned boolean3 : 1;
unsigned boolean4 : 1;
};
You can then easily edit each boolean value separately, for example:
struct foo example;
example.boolean1 = 1;
example.boolean2 = 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With