trying to simplify an algorithm

Hui Zhou zhouhui at
Tue Mar 1 06:58:17 PST 2005

On Tue, Mar 01, 2005 at 01:52:47PM +0000, Bennett Todd wrote:
>But relational operators that _create_ booleans --- ==, !=, <, >, et
>al --- create 0 or 1, strictly.

Indeed, that is specified in the ANSI C standard.

However, I am an advocate of use booleans as booleans. Utilizing the 
fact boolean is int in C seems nifty but obscures the readability.

I always frowns at statements such as 
    if (fopen(...))...
I prefer the usage:
    if (NULL != fopen(...))...

It is only a few more typings. There is no difference in the produced 
binary but the latter made it very clear that fopen returns integer 
and we are testing whether it is NULL. In case fopen returns -1 on 
error, the latter only need change NULL to -1. My point is the latter 
creates consistency, which eases reading.

Hui Zhou

More information about the lfs-chat mailing list