[net.lang.c] Crossing enumeration types

Schauble@MIT-MULTICS.ARPA (Paul Schauble) (06/08/86)

Is this program legal according to s strict interpretation of the new
ANSI standard? By common usage? Is this something lint should/does
complain about?

enum days {mon, tue,wed} day;
enum colors {red,green,blue} color;

main ()
{
    day = green;
    set_color (day);
}
set_color(thiscolor)
enum colors thiscolor;
{...
}

I expect at least two complaints about mixing types colors/days. Out
there in the big cruel world, how often am I going to be disappointed?

          Paul
          Schauble at MIT-Multics.arpa

guy@sun.UUCP (06/19/86)

> 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@sun.com (or guy@sun.arpa)