boolean datatypes

Alex Quilici alex at ucla-cs.ARPA
Wed Jun 18 03:03:53 AEST 1986


>The problems come when you write:
>
>	bool b;
>	int a, c;
>
>	b = (a == c);
>
>My compiler gives an "enumeration type clash".  It would seem that you
>can't legally convert integers to enum members...

yes, you can.  c just won't do the conversion for you automatically.
try using a cast:

       b = (bool) (a == c);

i frequently use enums to define constants that indicate various errors.
i find that whenever i have to worry about many errors

       typedef enum {NOPASS, BADRD, ... } ERROR;

is more convenient than 

	#define NOPASS 1
	#define BADRD  2
	   ...

i also find that my programs are more readable because the compiler
forces me to declare all variables or functions that hold or return
an error status to be of type ERROR, rather than simply int.

alex



More information about the Comp.lang.c mailing list