From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: enum Date: 21 May 2002 00:53:07 GMT Organization: Aachen University of Technology (RWTH) Lines: 33 Message-ID: References: <20020520160611 DOT 9371 DOT qmail AT web11307 DOT mail DOT yahoo DOT com> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 1021942387 21564 137.226.32.75 (21 May 2002 00:53:07 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 21 May 2002 00:53:07 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Pedro Izecksohn 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.