Mail Archives: djgpp/2002/05/20/21:04:04
Pedro Izecksohn <izecksohn AT yahoo DOT com> wrote:
> Because according to ANSI, in the code: "enum name {
> a,b,c,d } varname;", what is the purpose of "name" if to
> "a" is being attribed a value that is valid in all the file
> ?
Its purpose is so you can define a variable of type "enum name". In
suitable compilers, this will allow for more detailed checking of your
code. For example, let's assume code like this:
enum name { a, b, c, d, e, f};
...
enum name Name;
...
switch(Name) {
case a:
/*... */
case b:
/* ,... */
}
Compiling this in GCC with warnings turned on will give you a warning
that cases c, d, e and f are not handled in this switch. You'll also
get a warning if you assign a (compile-time constant) value to
variable "Name" that doesn't correspond to any of the enumerated ones.
Such warnings are not mandatory, i.e. they're not part of the language
definitions.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -