Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/17/84; site opus.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!hao!nbires!opus!rcd
From: rcd@opus.UUCP (Dick Dunn)
Newsgroups: net.lang.c
Subject: Re: if (X) <==> if (X != 0)  (enums)
Message-ID: <57@opus.UUCP>
Date: Wed, 18-Sep-85 02:46:31 EDT
Article-I.D.: opus.57
Posted: Wed Sep 18 02:46:31 1985
Date-Received: Fri, 20-Sep-85 06:28:16 EDT
References: <118@mit-hector.UUCP> <2792@sun.uucp> <173@myriasa.UUCP>
Organization: NBI,Inc, Boulder CO
Lines: 32

> We're going though the usual arguments about how the type 'boolean'
> should be fudged, and I came across this example:
> 
> typedef enum {FALSE, TRUE} bool;
> ...
>     if (flag) {
> ...
>     if (flag != 0) {
> ...
> The BSD 4.2 C compiler is happy about the first 'if', but warns about
> 'enumeration type clash' on the second. This at least is one case where
> 'if (X)' isn't the same as 'if (X != 0)'.

I remember Dennis Ritchie commenting about enums in C; the general idea was
that they were "ripp'd untimely from the womb" as it were, so there's woom
er, room, for improvement.  Some of the behavior of enums is for the dogs;
it's high time someone said, "Out, damn Spot!", got us off our MacDuffs, and
cleaned them up somehow.  I discovered, courtesy one of our local errant
programmers, that given a type:
	typedef enum {T0, T1, T2} ternary;
and a declaration:
	ternary t;
although it is not permitted, with the 4.x BSD compilers, to say:
	if (t!=0) ...
it IS permitted to say
	if (!t)
My reaction to the use of ! on a ternary value is, quid pro quo, !
If enums are ints, both ifs should be allowed; if they are distinct animals
(which I might hope had been the int-ention), neither should be allowed.
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Lately it occurs to me what a long, strange trip it's been.