DMD can implicitly convert class pointer to the bool. Is it bug or terrible feature?
deadalnix
deadalnix at gmail.com
Sun Nov 24 12:38:27 PST 2013
On Sunday, 24 November 2013 at 14:12:18 UTC, Maxim Fomin wrote:
> 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.
>
No, it is a comparaison with 0. If NULL is 0 on all modern
architectures I know of, this wasn't always the case.
> 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.
I'd like to know why this feature is dangerous as well.
More information about the Digitalmars-d
mailing list