Cro: Maintain it With Zig
Cro: Maintain it With Zig
Posted Sep 12, 2021 14:45 UTC (Sun) by HelloWorld (guest, #56129)In reply to: Cro: Maintain it With Zig by excors
Parent article: Cro: Maintain it With Zig
> I think that's incorrect, because it's legal to cast an integer to an "enum class" type even if it's not one of the declared enumerators.
The problem here is the cast, not the lack of a default clause. Why doesn't MISRA forbid that? That would actually make sense...
The problem here is the cast, not the lack of a default clause. Why doesn't MISRA forbid that? That would actually make sense...
Besides, what useful thing could you possibly do in such a default clause? Because after all, the whole point of an enum type is that it can only hold one of a number of enumerated values. Therefore, when you encounter a value that isn't among them, your program is already in a state that the developers didn't forsee, and hence couldn't possibly know how to rectify.
