Iddeed, most (all?) Compilers seem conceptually inconsistent when they usually warn of a possible loss of significant digits or accuracy (for example, in the case of conversion to int to char or similar), but make an exception for conversion to bool.
I assume that there are only historical reasons for this.
Many legacy code uses constructs such as
if (number) ... or if (pointer) ...
instead
if (number! = 0) ... or if (pointer! = NULL) ...
In addition, the latter style is often considered too verbose.
The tradition is convenient, it allows you to write compressed code, but it is really error prone. It is not supported (knowingly) in some other languages (e.g. Java).
source share