Problems with 64bit integer constant

Jeff Gilchrist

Usenet Archive
Joined
Jan 17, 2005
Messages
3
Reaction score
0
I have tried searching the newsgroup along with the GCC site and could not find what I think is probably a simple solution.

I am using a 64bit unsigned long long integer and can manipulate 64bits within the variable but I cannot assign a 64bit constant to it.

With my simple test program:

int main
{
unsigned long long test;

test = 18446744073709551606;
test = 0xFFFFFFFFFFFFFFF6;
}

I get the following errors with gcc v3.3.x and 3.4:

test.cpp:7: warning: this decimal constant is unsigned only in ISO C90 test.cpp:7: error: integer constant is too large for "long" type test.cpp:8: error: integer constant is too large for "long" type

I have also tried using variations with no success:
test = (unsigned long long)18446744073709551606;

There must be a way to do this, and it is probably just something simple that I am overlooking. Can anyone help?

Thanks.
 

Victor Bazarov

Usenet Archive
Joined
Sep 27, 2000
Messages
15,278
Reaction score
0
Jeff said:
I have tried searching the newsgroup along with the GCC site and could not find what I think is probably a simple solution.

I am using a 64bit unsigned long long integer and can manipulate 64bits within the variable but I cannot assign a 64bit constant to it.

With my simple test program:

int main
{
unsigned long long test;

There is no 'long long' data type in C++. There is in C99. Perhaps you need to post your question to the C newsgroup (comp.lang.c)?
test = 18446744073709551606;
test = 0xFFFFFFFFFFFFFFF6;
}

I get the following errors with gcc v3.3.x and 3.4:

test.cpp:7: warning: this decimal constant is unsigned only in ISO C90

The constant has a signed type _unless_ it has the U suffix. Try

test = 18446744073709551606U; // for "native" unsigned int

or

test = 18446744073709551606UL; // for "native" unsigned long

The constant is really too big to fit into a signed integer.
test.cpp:7: error: integer constant is too large for "long" type test.cpp:8: error: integer constant is too large for "long" type

I have also tried using variations with no success:
test = (unsigned long long)18446744073709551606;

There must be a way to do this, and it is probably just something simple that I am overlooking. Can anyone help?

If your _C++_ compiler natively supports 64-bit numbers, then it would be under 'unsigned long' type, and not 'unsigned long long'. Otherwise, this is a wrong forum to ask about it. Try gnu.g++.help.

Victor
 

Jeff Gilchrist

Usenet Archive
Joined
Jan 17, 2005
Messages
3
Reaction score
0
Victor said:
There is no 'long long' data type in C++. There is in C99. Perhaps you need to post your question to the C newsgroup (comp.lang.c)?

You are right of course. I sometimes forget which things are in the C standard and which are in the C++ since most C++ compilers treat C code as a substet of C++ and its hard to tell the difference.

For people with 32bit processors, how does one create a 64bit data type in C++ if 'int' and 'long' are both treated as 32bit in the compiler(s)?

Thanks,
Jeff.
 

Victor Bazarov

Usenet Archive
Joined
Sep 27, 2000
Messages
15,278
Reaction score
0
Jeff said:
[..]
For people with 32bit processors, how does one create a 64bit data type in C++ if 'int' and 'long' are both treated as 32bit in the compiler(s)?

Usually that's achieved by means of some language extensions. E.g., VC++ has '__int64' and 'unsigned __int64' that can be used. Constants of these types have non-standard suffixes 'i64' and 'ui64'.

V
 

Rolf Magnus

Usenet Archive
Joined
Jun 25, 2003
Messages
3,487
Reaction score
0
Victor said:
Jeff said:
[..]
For people with 32bit processors, how does one create a 64bit data type in C++ if 'int' and 'long' are both treated as 32bit in the compiler(s)?

Usually that's achieved by means of some language extensions. E.g., VC++ has '__int64' and 'unsigned __int64' that can be used.

And gcc has 'long long' and 'unsigned long long'.
Constants of these types have non-standard suffixes 'i64' and 'ui64'.

What do you mean by "non-standard suffixes"?
 

Victor Bazarov

Usenet Archive
Joined
Sep 27, 2000
Messages
15,278
Reaction score
0
Rolf said:
Victor Bazarov wrote:

Jeff said:
[..]
For people with 32bit processors, how does one create a 64bit data type in C++ if 'int' and 'long' are both treated as 32bit in the compiler(s)?

Usually that's achieved by means of some language extensions. E.g., VC++ has '__int64' and 'unsigned __int64' that can be used.

And gcc has 'long long' and 'unsigned long long'.

Constants of these types have non-standard suffixes 'i64' and 'ui64'.

What do you mean by "non-standard suffixes"?

AFAIK, there are no standard suffixes 'i64' and 'ui64'. There are 'L', 'U', 'UL', 'F'. And by "constants" I actually meant "literals". My bad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top