DMD can implicitly convert class pointer to the bool. Is it bug or terrible feature?
Maxim Fomin
maxim at maxim-fomin.ru
Sun Nov 24 06:12:17 PST 2013
On Sunday, 24 November 2013 at 14:02:43 UTC, ilya-stromberg wrote:
> On Sunday, 24 November 2013 at 13:57:22 UTC, Maxim Fomin wrote:
>> This is neither bug not a terribale feature. Have you coded in
>> C?
>
> Yes, only a little. I like D because it dissallow most of
> dangerous abbilities. We already have `is` operator for pointer
> comparison. Class doesn't provide cast to bool. So, why it's
> allowed?
void* ptr;
if(ptr)
was a shortcut for 'if(ptr != NULL)' probably since C was created.
There is no problem with classes or pointers convertion to
booleans in condition statements, it is not a dangerous ability.
Is operator is not restricted to pointer comparison, you can use
it to bitwise compare any objects.
More information about the Digitalmars-d
mailing list