473,569 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with 64bit integer constant

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 = 184467440737095 51606;
test = 0xFFFFFFFFFFFFF FF6;
}

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)1844674407 3709551606;

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

Thanks.

Jul 22 '05 #1
7 17191
Jeff Gilchrist wrote:
test = 184467440737095 51606;
test = 0xFFFFFFFFFFFFF FF6;


Add the suffix "LLU" to the constants and it should work for you.

-- John
Jul 22 '05 #2
Jeff Gilchrist wrote:
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 = 184467440737095 51606;
test = 0xFFFFFFFFFFFFF FF6;
}

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 = 184467440737095 51606U; // for "native" unsigned int

or

test = 184467440737095 51606UL; // 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)1844674407 3709551606;

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
Jul 22 '05 #3
Victor Bazarov wrote:
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.

Jul 22 '05 #4
John Valko wrote:
Add the suffix "LLU" to the constants and it should work for you.

Thanks John, works like a charm.

Much appreciated,
Jeff.

Jul 22 '05 #5
Jeff Gilchrist wrote:
[..]
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
Jul 22 '05 #6
Victor Bazarov wrote:
Jeff Gilchrist wrote:
[..]
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"?

Jul 22 '05 #7
Rolf Magnus wrote:
Victor Bazarov wrote:

Jeff Gilchrist wrote:
[..]
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.
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3230
by: Christian McArdle | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.os.ms-windows.programmer.64bit This is a formal Request For Discussion (RFD) to create comp.os.ms-windows.programmer.64bit as an unmoderated world-wide Usenet newsgroup dedicated to the discussion of Microsoft Windows 64-bit programming. This is not a Call for Votes (CFV); you cannot vote...
29
15641
by: SysSpider | last post by:
Hi again, This is my problem: when i try to compile the code that contains the function below, i get this: -- gcc:21: error: case label does not reduce to an integer constant gcc:24: error: case label does not reduce to an integer constant --
6
35658
by: fctk | last post by:
hello, i'm trying to compile this small program: int main(void) { unsigned long int max; max = 4000000000;
6
2135
by: yxq | last post by:
Hello, The File.Delete(VS2005) function can not delete file on Vista-64bit, why? And, what changes of API between 32-bit and 64-bit? Thank you
1
6261
by: Thomas Kehl | last post by:
Hello. I use the fallowing Functions to send Message from one Application to another. This is working correct on a 32bit System. But on a 64Bit System, the Target-Application will no received anything. Can somebody help me, what I am doing wrong? Private Const _messageID As Integer = -11678085939 Public Const WM_COPYDATA As Integer =...
17
1846
by: matevzb | last post by:
I've ran into some fishy code that, at first glance, is buggy, but it seems to work correctly and none of the compilers I've tried (five so far, on various systems) gives any warnings. The code: ============================ #include <stdio.h> void fcn (char *str)
18
3916
by: cman | last post by:
Hi guys, why does this fail raising bad_alloc int *v = new int ; if this succeeds int *v = (int *) malloc((unsigned)6000000000) both on the same machine, same compiler g++, 64bit linux red hat enterprise 4, no ulimits on the user, enough virtual memory ecc... in both cases compiled with
2
2160
by: M O J O | last post by:
(I'm using Visual Studio 2008) I want my new develloper pc to be Vista 64bit, but all my clients are so far 32bit (XP), so my questions are: 1) Is it possible for me to tell VS2008 that the output should be 32bit? That is devellop dotnet on a 64bit machine and output 32bit program? 2) When later this year, all my clients are updgraded...
0
1270
by: yxq | last post by:
Hello, The code below can popup the property dialog of a file, it works well on XP, Vista 32bit, but it will not work on Vista 64bit, how to correct it? i have tried to change integer to intptr, but not work yet, thank you. //////////////////////////////////////////////////////...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.