if (X) <==> if (X != 0)

Chris Gray cg at myriasa.UUCP
Sat Sep 14 02:26:50 AEST 1985


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;

f()
{
    bool flag;

    if (flag) {
	printf("Hello\n");
    }
    if (flag != 0) {
	printf("Good-bye\n");
    }
}

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)'.

				Chris Gray   {...,ihnp4}!alberta!myrias!cg



More information about the Comp.lang.c mailing list