NULL v. zero
Posted Jul 16, 2004 20:15 UTC (Fri) by
ikm (subscriber, #493)
In reply to:
NULL v. zero by Ross
Parent article:
NULL v. zero
First of all, it is the fact that the language is strongly typed that allows it using 0 for anything, but not the opposite.
There is no magic. A zero constant may be implicitly casted either to a null pointer, or to a zero integer. The compiler deduces which cast is required judging by the target type. An integer can not be implicitly casted to a null pointer, as well as any non-zero integer constant. Only a zero integer constant may be casted to a pointer. It is quite simple really.
When the target type is ambiguous (e.g. with overloaded functions), the compiler will stop with an error. In this case you will have to cast your zero either to an integer type or to a pointer type explicitly. This behaviour is common with overloaded functions, and is nothing special for pointers.
(
Log in to post comments)