(Some compilers actually do some sort(s) of extra checking. No
diagnostics are required here, but compilers are always allowed to
produce as many warning messages as the compiler-writer wants.
Whether or not those extra warning are good or desirable is another
question entirely....)
An enum type is a symbolic name for an int. Declaring
Well, not quite. The enumeration *members* are names for "int"s,
but the enumerated *type* -- here "enum Side" -- is not necessarily
an int. Some compilers either always, or optionally, shorten the
type to the smallest one that will hold its members. (With gcc,
use "-fshort-enum" to turn this on.)
enum Side a;
is simply declaring 'a' to be an int.
Or perhaps a "char" or "unsigned char":
enum A { Zero, One_twenty_seven = 127 }; /* always fits in char */
enum B { Two_fifty_five = 255 }; /* always fits in unsigned char */
enum C { Three_two_seven_six_seven = 32767 }; /* always fits in int */
I have not studied the C99 text closely yet, but my reading of the
C89 standard appears to me to allow even "enum C" to use an unsigned
char, despite the fact that one should be able to do:
enum C x = Three_two_seven_six_seven;
and on real implementations, that would make x have the value 127.
(I would hope that any compiler that did this, even if the C
standards do allow it, would not survive in the marketplace....)
Note that:
enum D { Large = 2147483647 };
is OK if and only if INT_MAX is at least 2147483647, e.g., typical
32-bit systems today. In other words, you can use this in a 32-bit
compiler but not in a 16-bit compiler. (I believe some compilers
have extensions to allow "enum"s to contain long and/or long long
members, but this *is* an extension; the C standards -- C89 and
C99 both -- do not require it.)