Memory safe in D

Doigt labog at outlook.com
Wed Apr 17 02:29:22 UTC 2024


On Tuesday, 16 April 2024 at 22:15:42 UTC, ShowMeTheWay wrote:
> int b;
> writeln(b);
>
> The compiler should require you to assign to 'b' before using 
> it.
>
> On the otherhand, this below should *not* get the compilers 
> attention:
>
> int b = int.init;
> writeln(b);

Not a bug. Variables that aren't explicitly assigned a value have 
default values that are implicitly assigned to them. Those are 
the same default values used for arrays and struct/class fields. 
So in theory, you should know about them because they are 
unavoidable elsewhere even if implicit value assignment was 
turned off.


More information about the Digitalmars-d mailing list