1) The fact is that in all cases in the C language, the compiler does not check the value as enum.
I canβt understand what you are saying to your tribe.
1) In all cases in the C language, the compiler does not check the value of the enumeration. [Edit]
When you appoint him. Assignment from bare integers is allowed, so you can do:
enum E { A, B } x; x = 10000;
without compiler error. In addition, switch es in enumerations do not check comprehensive information.
2) Why are enumeration constants not checked for some reason? What are these reasons?
People like to insert integers into them. eg.
enum E { END_OF_EVERYTHING = 5 };
where 0-4 mean like ordinary values, and 5 is special.
3) Since enum is not checked by the compiler, is using enum error prone?
Yes. Since enumerations have only the least number of bits that all enumeration values ββcan take, you can get strange results:
enum E { A = 1, B = -1 };
This enumeration contains only 2 bits of data (values ββ-2, -1, 0, 1). If you enter 10,000 into it, strange things (actually seen) can happen.
jpalecek
source share