Not a compiler bug.

mw mingwu at
Thu Aug 13 07:56:31 UTC 2020

On Thursday, 13 August 2020 at 07:51:06 UTC, FeepingCreature 
> "Not a bug." Or rather, same semantics as in C. The division 
> reinterprets a as unsigned, and the result is within the 
> positive range of a long, so it stays positive post-division.

Let me add all my post together:

It can NOT silently do this, at least a warning.

BTW, on Windows, dmd correctly output -2500.

Just because C/C++ did it doesn't means it's correct.

And D supposed to be an improvement of C++.

OK, let me write this in this way to show it's impact:
import std.algorithm;
import std.stdio;

void main() {
   long[] a = [-5000, 0];
   long   c = sum(a) / a.length;

$ ./divbug

More information about the Digitalmars-d mailing list