Disallow null references in safe code?
deadalnix
deadalnix at gmail.com
Sat Feb 1 16:40:16 PST 2014
On Saturday, 1 February 2014 at 20:03:40 UTC, Jonathan M Davis
wrote:
> In the general case, you can only catch it at compile time if
> you disallow it
> completely, which is unnecessarily restrictive.
That is not accurate. The proposal here propose to make it
@system instead of disallowing it completely. Even looser, I
propose to make @system reference passing that can be null
through interface (function calls/return mostly). So you can use
null locally, where the compiler can check you do not dereference
it, and ensure that data coming from somewhere else is not null,
unless specified as such.
> Sure, some basic cases can be
> caught, but unless the code where the pointer/reference is
> defined is right
> next to the code where it's dereferenced, there's no way for
> the compiler to
> have any clue whether it's null or not. And yes, there's
> certainly code where
> it would make sense to use non-nullable references or pointers,
> because
> there's no need for them to be nullable, and having them be
> non-nullable
> avoids any risk of forgetting to initialize them, but that
> doesn't mean that
> nullable pointers and references aren't useful or that you can
> catch all
> instances of a null pointer or reference being dereferenced at
> compile time.
>
> - Jonathan M Davis
More information about the Digitalmars-d
mailing list