On Wed Feb 1 20:32:51 2023 +0000, Gabriel Ivăncescu wrote:
that's not what enums are for.
I disagree. Using enums for flags is pretty idiomatic and certainly the best way to store flags, if they are a proper fit for the constraints imposed by the type (because unfortunately C does not have enums like C++ where you can specify the underlying type, so it won't work if you need a specific bit width to match some ABI or other constraints). The alternative is using preprocessor macros, which not only pollutes the global namespace (hence the ALL CAPS notation), but far more importantly, it's a lot harder to understand from the type what flags it actually uses. With the enum you simply look up the enum from the variable type, and it might even come with comments describing each of them and what other flags are available. IMO the benefits far outweight the potential confusion from the "name" of it or the fact it's sequential by default (but by using preprocessor macros you have to specify the value on each flag, anyway…). I mean, it's C, not English. ;)
IMO it is absolutely matter of personal preference whether to prefer enum or #define (minus theoretical issue with 64 bit flags but I don't think we need those here). I always respect the desire of maintainer to see it one way or another in the code they maintain and never argue on that. Of course the things get a bit more complicated when there are two maintainers, but I am sure we can figure something even better, like just return bool flag in this case :)