trouble with long
eles
eles at eles.com
Tue Jul 16 03:37:58 PDT 2013
$cat test.cpp:
#include <iostream>
int main() {
long long x = 1250000000 * 2;
std::cout << x << std::endl;
return 0;
}
g++-generated exe displays: -1794967296
$cat test.d:
import std.stdio;
int main() {
long x = 1250000000 * 2;
writefln("%d",x);
return 0;
}
dmd- and gdc-generated exes display: -1794967296
compiling with g++ at least gives a warning:
warning: integer overflow in expression [-Woverflow]
long long x = 1250000000 * 2;
Both dmd and gdc do not complain in any way.
Isn't the promotion to int so awful? Better ideas? (yes, I know
about casting to long).
More information about the Digitalmars-d-learn
mailing list