trouble with long
Simen Kjaeraas
simen.kjaras at gmail.com
Tue Jul 16 03:47:42 PDT 2013
On Tue, 16 Jul 2013 12:37:58 +0200, eles <eles at eles.com> wrote:
> $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).
This is where integer suffixes can help:
long x = 1250000000L * 2;
--
Simen
More information about the Digitalmars-d-learn
mailing list