C programming syle poll

Doug Gwyn gwyn at brl-vgr.ARPA
Wed May 2 08:01:55 AEST 1984


	x == 5
evaluates to 1 (nothing else!) if true, 0 if false.

However, I agree that
	y = x == 5;
is poor programming practice IF Y IS AN INT.  It is perfectly okay if
you make the distinction between ints and Booleans, and is common
practice in well-written Pascal and even Fortran.  E.g.

typedef int	bool;

foo()
{
	register bool	y;
	int		x;

	...
	y = x == 5;
	...
	if ( y )
		...
}

I recommend AGAINST performing arithmetic with Booleans (i.e., using
a Boolean datum as a numerical 1 or 0); this is illegal in other
Algol-based languages and comes under the heading of "tricky" coding.

I religiously keep ints and Booleans distinct in my code and have
found that it helps keep the code clean and understandable.



More information about the Comp.lang.c mailing list