Why LDC drop d_with_sum code? (windows)

Dennis dkorpel at gmail.com
Tue May 28 12:33:33 UTC 2019


On Tuesday, 28 May 2019 at 10:43:38 UTC, KnightMare wrote:
> DMD & LDC change d_with_sum(...) to "return .0"
> why?

Because you are summing an empty array.

```
double d_with_sum(double[] values) @safe pure nothrow
{
     import std.algorithm : sum;
     double[] squares;
     squares[] = values[] * values[];
     return squares.sum;
}
```

`squares` is initialized with length and pointer 0, and the 
values[] * values[] gets truncated to the size of the destination 
memory, so it becomes a no-op.


More information about the digitalmars-d-ldc mailing list