Crossing enumeration types

guy at sun.UUCP guy at sun.UUCP
Fri Jun 20 05:01:36 AEST 1986


> enum days {mon, tue,wed} day;
> enum colors {red,green,blue} color;
> 
> main ()
> {
>     day = green;
>     set_color (day);
> }
> set_color(thiscolor)
> enum colors thiscolor;
> {...
> }
>
> Is this program legal according to s strict interpretation of the new
> ANSI standard?

Yes.  "enum"s are just fancy integral types, whose values have names.

> By common usage?

Yes, in the sense that the code will compile and do what you'd expect it to
do given that "enum"s are fancy "int"s.

> Is this something lint should/does complain about?

It does complain; I would argue that it should.  The complaints should be
warnings, since the code is technically correct.  However, the code stands a
good chance of being in error anyway, so the complaints are justified.
Casts should suppress the complaint, so that if this is what the person
intended to do they can say so.

-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list