DMD can implicitly convert class pointer to the bool. Is it bug or terrible feature?
ilya-stromberg
ilya-stromberg-2009 at yandex.ru
Sun Nov 24 05:49:24 PST 2013
Code examle:
import std.stdio;
class Foo
{
}
void main()
{
Foo f;
if(f)
{
writeln("f is true");
}
else
{
writeln("f is false");
}
f = new Foo();
if(f)
{
writeln("f is true");
}
else
{
writeln("f is false");
}
}
Programm output:
f is false
f is true
So, pointer implicitly converts to false if pointer is null and
to true if pointer is not null. Is it bug or terrible feature?
Note that we have `f is null` syntax for these cases.
More information about the Digitalmars-d
mailing list