Memory safe in D

Nick Treleaven nick at geany.org
Mon Mar 18 12:31:23 UTC 2024


On Saturday, 16 March 2024 at 19:10:56 UTC, Don Allen wrote:
> The compiler therefore forces you to handle the unusual case, 
> so if it happens, the result will be something under your 
> control.

You can call `unwrap` on the Option which will panic if it's 
None. But that's fine, because that call makes it clear to anyone 
reading the code that the programmer is intentionally assuming 
the Option contains a value.

...
> Related to the above, you may also process an uninitialized 
> value, at which point anything can happen.

It can't violate memory safety:

> Void initializers for variables with a type that may contain 
> unsafe values (such as types with pointers) are not allowed in 
> @safe code.

https://dlang.org/spec/declaration.html#void_init



More information about the Digitalmars-d mailing list