c simply accepts just about anything as a Boolean test when not applying a Boolean to it..
I think this would be a great step for fpc to be able to have auto Boolean parsing during the expression phase.
C does not accept anything as boolean, in C there is no such thing as boolean, it is just int. Anything that can implicetly be converted to int does the job, this includes pointer and floats.
About that boolean parsing, well... it exists kinda thanks to operator overloading, take this simple class I've wrote:
TOptional<T> = record
[...]
public
function Get: T; {$IFDEF INLINING}inline;{$ENDIF}
[...]
class operator Implicit(constref opt: TOptional<T>): Boolean; {$IFDEF INLINING}inline;{$ENDIF}
class operator Explicit(constref opt: TOptional<T>): Boolean; {$IFDEF INLINING}inline;{$ENDIF}
class operator LogicalNot(constref opt: TOptional<T>): Boolean; {$IFDEF INLINING}inline;{$ENDIF}
[...]
end;
Thanks to the operator Implicit to boolean one can simply write such code:
if someOptional then
someOptional.Get.DoSomething;
And with the operator not the following is possible:
if not someOptional then
raise EObjectNotFoundException.Create(...);
While being a little bit cumbersome (especially with the not operator) this works pretty fine. In C++ there is the operator bool that can directly convert a value to bool and therefore enables all the logical operators like not, and, etc, which is not so easiely possible in pascal because C++ handles bools a little bit seperately (while in pascal you would need to overload every combination of and- or and xor with all types you want to couple that with, I for my part therefore usually only overload the implicit, explicit and not and ignore the other operators)