▲ | RaftPeople 5 days ago | |||||||
> The best way in many languages for flags is using unsigned integers that are botwise-ORed together. Why is that the "best" way? | ||||||||
▲ | lelanthran 5 days ago | parent | next [-] | |||||||
> Why is that the "best" way? "Best way" is often contextual and subjective. In this context (boolean flags to a function), this way is short, readable and scoped, even in C which doesn't even have scoped namespaces. Maybe there are better ways, and maybe you have a different "best way", but then someone can legitimately ask you about your "best way": `Why is that the "best" way?` The only objective truth that one can say about a particular way to do something is "This is not the worst way". | ||||||||
▲ | waste_monk 5 days ago | parent | prev [-] | |||||||
It's simple, efficient, and saves space in memory. While not as big a deal these days where most systems have plentiful RAM, it's still useful on things like embedded devices. Why waste a whole byte on a bool that has one bit of data, when you can pack the equivalent of eight bools into the same space as an uint8_t for free? | ||||||||
|