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 20:20:23 PST 2013


On Sunday, 24 November 2013 at 21:13:12 UTC, deadalnix wrote:
> On Sunday, 24 November 2013 at 21:00:53 UTC, Maxim Fomin wrote:
>> 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?
>
> http://c-faq.com/null/machexamp.html

You confused runtime bit pattern and zero integer constant. NULL 
is always zero integer constant (probably casted to void*) by 
definition.

http://c-faq.com/null/varieties.html

if(ptr) is as good as if(ptr != 0) or if(ptr != NULL) regardless 
of null bit pattern

"The internal (or run-time) representation of a null pointer, 
which may or may not be all-bits-0 and which may be different for 
different pointer types. The actual values should be of concern 
only to compiler writers. Authors of C programs never see them, 
since they use..The null pointer constant, which is a constant 
integer 0 "


More information about the Digitalmars-d mailing list