[OT] Some neat ideas from the Kotlin language
Xinok via Digitalmars-d
digitalmars-d at puremagic.com
Tue Feb 23 14:03:32 PST 2016
On Tuesday, 23 February 2016 at 19:43:43 UTC, rsw0x wrote:
> ...
> How does this differ from the example I gave where the branch
> is only taken if the pointer is non-null?
D doesn't prevent you from dereferencing a null pointer whereas
these scenarios should be impossible in Kotlin as well as Rust.
Case and point, this code compiles without issue but crashes at
runtime:
int* foo()
{
return null;
}
void main()
{
if(int* ptr = new int)
{
ptr = foo(); // Whoops...
*ptr = 35; // Crash
}
}
In D, pointers and reference types can spontaneously become null
under almost any context. That's the difference.
More information about the Digitalmars-d
mailing list