strange effects with enumerated types

Guy Harris guy at auspex.UUCP
Wed Oct 19 11:26:46 AEST 1988


>why does the compiler (I don't know which compiler it is. I assume it is
>the standard one supplied with a SUN 3/50)

...which is based on PCC or its descendants, like many (most?) UNIX C
compilers, so I suspect this bug may exist in other UNIX C compilers as
well...

>produce this result and is it a bug of this compiler or a "feature" of C ?

According to K&R, second edition (which includes stuff from a recent
ANSI C draft):

	   Enumerator names in the same scope must all be distinct from
	each other and from ordinary variable names, but the values need
	not be distinct.

I infer from K&R 2 that the scope of the "enum" in "new_struct" is the
entire source file and the scope of the "enum" in "*p" to be the
function "test_fn1".  Now, K&R 2 also says

	   If an identifier is explicitly declared at the head of a block,
	including the block constituting a function, any declaration of
	the identifier ouside the block is suspended until the end of
	the block.

>From that, I infer that the declaration "a", "b",and "c" in the
definition of "new_struct" should be suspended inside the block
constituting "test_fn1", so that this is a compiler bug.



More information about the Comp.bugs.4bsd.ucb-fixes mailing list