null in D

bearophile bearophileHUGS at lycos.com
Tue Aug 19 07:05:32 PDT 2008


This is the C FAQ:
ftp://ftp.eskimo.com/u/s/scs/C-faq/faq.gz
at the point 5.2: it says:

>an argument being passed to a function is not necessarily recognizable as a pointer context, and the compiler may not be able to tell that an unadorned 0 "means" a null pointer.  To generate a null pointer in a function call context, an explicit cast may be required<
(Later the FAQ also explains why).

So essentially in C this is the right thing to call foo() that takes a pointer to int (using 0 instead of NULL is the same):
foo((int *)NULL);

So in D is this better, like in C:
foo((int *)null);

Or is this always enough in D?
foo(null);

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list