471,578 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,578 software developers and data experts.

C++: integer constant is too large for "long" type

Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following
message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine.
So what can I do to fix the problem?

Thanks,
Jo

Aug 10 '07 #1
7 6896
On Aug 9, 9:01 pm, Jo Deni <joachim_denin...@web.dewrote:
Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following
message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine.
So what can I do to fix the problem?

Thanks,
Jo
try "long long" or "__int64" or "long double" instead of "double"

Aug 10 '07 #2
On Thu, 09 Aug 2007 20:01:44 -0700, Jo Deni wrote:
Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine. So what can I do to fix the
problem?

Thanks,
Jo

don't you mean

double X = 1.0e10;
The compiler is trying to parse 10000000000 as an integer constant and it
cannot do so.
Aug 10 '07 #3
Jo Deni wrote:
Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following
message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine.
So what can I do to fix the problem?
Try

double X = 10000000000.0;
Best

Kai-Uwe Bux
Aug 10 '07 #4
On Aug 10, 12:01 pm, Jo Deni <joachim_denin...@web.dewrote:
double X = 10000000000;
The execution for X = 10^9 worked fine.
So what can I do to fix the problem?
Hi Jo,

I think your compiler would first parse all elements in your program,
and consider the number to be a 32 bit integer (at which time there's
a problem), then later try to "promote" it to a double for assignment
into X. Just write the number as a floating pointer constant to begin
with: 1E10 or 1000000000000.0.

Tony

Aug 10 '07 #5
On Aug 9, 10:01 pm, Jo Deni <joachim_denin...@web.dewrote:
Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following
message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine.
So what can I do to fix the problem?

Thanks,
Jo
10000000000 is trying to be a literal 'int', which is implicitly
converted to the double X. You get the error as 10000000000 is too
large for a 32 bit int. If you use:

double X = 10000000000.0;

it should be fine.

Steve.

Aug 10 '07 #6
and here is the offending line in my code
>
double X = 10000000000;

So what can I do to fix the problem?
double X = 10000000000LL;

Aug 10 '07 #7
On Aug 11, 3:52 am, 440...@email.com wrote:
and here is the offending line in my code
double X = 10000000000;
So what can I do to fix the problem?

double X = 10000000000LL;
LL is not defined in the current C++ standard.
Your compiler might support it as an extension,
but it would be better to use 1E10 or 10000000000.0 .

Aug 12 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Adam Ierymenko | last post: by
22 posts views Thread by Vijay | last post: by
12 posts views Thread by Zero | last post: by
28 posts views Thread by silvia.fama | last post: by
3 posts views Thread by ext | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.