Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Do not default the test for non-zero.
Essentially,

Code Block

#define FAIL 0

if (foo() != FAIL) ...

is preferable to

Code Block

#define FAIL 0

if (foo()) ...

despite the fact that C considers 0 to be false. The first will be beneficial if it is later decided that a failure return should be -1 rather than 0.

Performing explicit tests to determine success, true/false, and equality makes code both maintainable and compliant with common conventions.
In the case that the return value will never change, an explicit test is still preferable to clearly communicate the numeric, rather than boolean, value of the test.

This recommendation is derived from and considers the implications of the following common conventions:

...