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 13:00:51 PST 2013
On Sunday, 24 November 2013 at 20:38:29 UTC, deadalnix wrote:
> 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.
>
It is comparison with NULL and zero (I though it is obvious that
the code snippet is written in C), because NULL is always zero by
definition ("an integer constant expression with the value 0, or
such an expression casted to void*"). If this is not the case,
then implementation is broken. Which of them you are talking
about?
More information about the Digitalmars-d
mailing list