New blog post featuring D

Siarhei Siamashka siarhei.siamashka at gmail.com
Tue Jan 23 21:53:54 UTC 2024


On Tuesday, 23 January 2024 at 09:58:53 UTC, Patrick Schluter 
wrote:
> You shouldn't advertise -release flag as long as it does "wrong 
> thing"™ like removing array bound checking and assertions (it 
> is contradictory to your normal memory safety stance).

The "-release" option removes bounds checking from the unsafe 
code, but keeps them in the code that is annotated as `@safe`. 
The only problem is that `@safe` is not the default function 
attribute in D. So all samples from the blog post need a `@safe:` 
line added in the beginning of the source file to opt-in the 
safety. The first sample would turn into:

```D
@safe:
import std.string;
import std.process;

int main(string[] args) {
     string[] av = new string[args.length + 2];
     av[0] = "/usr/bin/cc", av[1] = "-xassembler", av[2] = "-c";

     size_t ac = 3;
     foreach (i; 1 .. args.length)
         av[ac++] = args[i];

     return spawnProcess(av).wait();
}
```

Also there's an error in one of the samples:
```D
int main(strings[] args) {
```



More information about the Digitalmars-d mailing list