Memory safe in D

Alex akornilov.82 at mail.ru
Mon Mar 11 10:20:58 UTC 2024


On Monday, 11 March 2024 at 08:48:47 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> 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.

Oh... looks like null is also used for refs in D. It's sad :)
I thought it used only for pointers in unsafe mode.
I think, the null safety feature is very important in modern 
world (maybe "must have" :) ). Very nice to have such feature in 
D like in Kotlin for example.
So, as I understand, D team have the task in TODO list about 
implementation something like "null safety"?



More information about the Digitalmars-d mailing list