Casting from int to long
Yui Hosaka
hos at hos.ac
Mon Nov 18 15:16:11 UTC 2019
On DMD32 D Compiler v2.089.0-dirty, Windows, the code
----
import std.stdio;
int f(int x) {
return 1;
}
void main() {
enum N = 100;
auto a = new int[N];
a[] = 1;
long sum;
foreach_reverse (i; 0 .. N) {
const r = i % 5;
sum += cast(long)(a[i]) * f(r);
}
writeln(sum);
}
----
gives the output 950, while it should be 100. This happens only
with -O and without -m64 option.
I have encountered some kind of "32-bit / 64-bit issues" several
times (https://issues.dlang.org/show_bug.cgi?id=20162,
https://issues.dlang.org/show_bug.cgi?id=20128).
More information about the Digitalmars-d-learn
mailing list