Memory safe in D

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Mon Mar 11 08:48:47 UTC 2024


On 11/03/2024 9:16 PM, Alex wrote:
> So I don't see any errors or warnings from compiler when I use 
> uninitialized variable |a| and don't see any exception with backtrace in 
> runtime (application is build in debug mode).
> 
> Is it expected behavior? Looks like it is not very safe approach and can 
> lead to very unpleasant memory errors...

This is expected behavior.

The variable a was default initialized to null.

D has not got type state analysis as part of it, so it cannot detect 
this situation and cause an error.

It is at the top of my todo list for memory safety research for D, as 
the IR it requires enables other analysis and provides a framework for 
it to exist in.


More information about the Digitalmars-d mailing list