Memory safe in D
Basile B.
b2.temp at gmx.com
Wed Apr 17 00:25:07 UTC 2024
On Tuesday, 16 April 2024 at 22:15:42 UTC, ShowMeTheWay wrote:
>
> btw. This too is a likely bug:
>
> 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);
Both are semantically equivalent. The first version is about
knowing how the language works, the second is about being stupid.
D policy about default initializers is really to create clear
poison value. You still have "void initialization" if you want to
introduce UBs.
```d
int b = void;
writeln(b);
```
that is more what should get the compiler attention.
More information about the Digitalmars-d
mailing list