[comp.lang.c] enum redeclaration

dlong@midgard.ucsc.edu (Dean Long) (10/08/89)

enum {A, B, C};
enum {A, B, C, D};
enum {B = 1, C, X};

Question: are the second and third declarations OK, assuming that
all three are in the same scope?

The reason I ask this is that I believe the enum bug fix for 4.3 PCC posted
in comp.bugs.4bsd changes the behavior of the compiler so that the
above declarations are allowed.  Without the enum bug fix, the
second and third will get redeclaration errors.
----------------------------
Dean Long 	dlong@midgard.ucsc.edu

dfp@cbnewsl.ATT.COM (david.f.prosser) (10/09/89)

In article <5648@portia.Stanford.EDU> dlong@midgard.ucsc.edu (Dean Long) writes:
>enum {A, B, C};
>enum {A, B, C, D};
>enum {B = 1, C, X};
>
>Question: are the second and third declarations OK, assuming that
>all three are in the same scope?
>
>The reason I ask this is that I believe the enum bug fix for 4.3 PCC posted
>in comp.bugs.4bsd changes the behavior of the compiler so that the
>above declarations are allowed.  Without the enum bug fix, the
>second and third will get redeclaration errors.

Or, putting it another way, if an enum constant gets redeclared in
the same scope, is it okay if it's given the same value?

According to the pANS section 3.5, constraints:

	If an identifier has no linkage [enum constants have no linkage],
	there shall be no more than one declaration of the identifier (in
	a declarator or a type specifier) with the same scope and in the
	same name space, except for tags as specified in 3.5.2.3.

Since there's nothing under enumeration specifiers that makes a special
case (as there is with tags), a diagnostic must be issued in the above
example, independent of the value associated with the enum constants.

However, that doesn't mean that a compiler cannot choose to make this a
"soft" error and continue compiling since "no harm" has been done.

Dave Prosser	...not an official X3J11 answer...