473,732 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

64 bit integer

Jay
Hello, I am sure this has a quick and easy solution but I can't find
it.

I need to store 19 '9's in an integer which means i need an unsigned 64
bit
integer.
in Visual Studio the code would be:

__int64 test = 999999999999999 9999;

I am using g++ version 3.3.5(suse 9.3) and have tried both:

unsigned long long test = 999999999999999 999;
and:
uint64_t test = 999999999999999 9999;

both have this compile error using the command "g++ test.cpp"
test.cpp:5: error: integer constant is too large for "long" type

Am I forgeting to include something or not passing an option to g++, or
is
there another way to do 64 bit integer storage?

Thank you for your help

Dec 7 '05
20 34737
Ja**********@gm ail.com wrote:
unsigned long long a = 999999999999999 9999LLU; is the right way to do
it. If you don't say it's unsigned you get warnings because it's too
large.

That works fine for 64 bit numbers on 32 bit machine.


long long is a compiler extension. It is not standard and will not work
on all platforms or compilers. long is guaranteed to be at least 32
bits by the standard; that's as big as it gets as far as the standard
is concerned (for now).

Cheers! --M

Dec 7 '05 #11
On 2005-12-07 11:23:19 -0500, Ja**********@gm ail.com said:
unsigned long long a = 999999999999999 9999LLU; is the right way to do
it.


That is, if your C++ compiler supports 'long long' as an extension.
While many do, remember that 'long long' is a feature of C99, *not* of
C++.

--
Clark S. Cox, III
cl*******@gmail .com

Dec 7 '05 #12

Jay wrote:
Hello, I am sure this has a quick and easy solution but I can't find
it.

I need to store 19 '9's in an integer which means i need an unsigned 64
bit
integer.
in Visual Studio the code would be:

__int64 test = 999999999999999 9999;

I am using g++ version 3.3.5(suse 9.3) and have tried both:

unsigned long long test = 999999999999999 999;
and:
uint64_t test = 999999999999999 9999;

both have this compile error using the command "g++ test.cpp"
test.cpp:5: error: integer constant is too large for "long" type

Am I forgeting to include something or not passing an option to g++, or
is
there another way to do 64 bit integer storage?


Yes. This is how the declaration should look:

unsigned long long test = 999999999999999 999ULL;

long long constants require an LL or ULL type designator. Although long
longs are not yet officially part of the C++ language they will be
added in the next revision.

Greg

Dec 7 '05 #13

mlimber wrote:
Ja**********@gm ail.com wrote:
unsigned long long a = 999999999999999 9999LLU; is the right way to do
it. If you don't say it's unsigned you get warnings because it's too
large.

That works fine for 64 bit numbers on 32 bit machine.


long long is a compiler extension. It is not standard and will not work
on all platforms or compilers. long is guaranteed to be at least 32
bits by the standard; that's as big as it gets as far as the standard
is concerned (for now).


long longs are part of the C99 standard and will be in the next
revision of the C++ standard.

It is C99, and not C++, that specifies the size of integer types. C++
makes no guarantee that any integer type will be larger than a byte.

Greg

Dec 7 '05 #14
Jay
Well I think I will go with the extension that doesn't require me to go
find another class to add to my code which should be simple for a
programing language as powerful as c++. I am disappointed that
everything I want to do for this project is an extension of c++. Maybe
I
should just report that the project is coded in a custom language. At
least it's working with long long, hopefully whatever commitee decides
on c++ standards will help me out someday, but until then, I'm going to
be a fan of extensions

Dec 7 '05 #15
Jay
Good to hear, I'm guessing that if it's known to be part of the next
revision, the compilers will have already put it in. So nothng to
really worry about there

Dec 7 '05 #16
Hi

Jay wrote:

[about long long]
Good to hear, I'm guessing that if it's known to be part of the next
revision, the compilers will have already put it in. So nothng to
really worry about there


But following the reasoning of your recent post elsewhere in this thread,
you would soon start crying that there is no type long long long that is
guaranteed to be at least 96 or 128 bits long. And if one would add this,
at some point the need for an 256 bits type would come up. A never-ending
story...

If you're targeting a specific platform, you're fine using whatever your
compiler offers you (i.e. extensions).

If you want a program that is standard compliant and thus
platform-independent, you will have to use some sort of arbitrary precision
library. (or at least a library that defines some sort of 64-bit integer (I
think boost does?))

If you're about to argue that this should be part of the standard library:
I'm with you there.

But please don't blame the language.

cheers
Markus

Dec 7 '05 #17
Jay
first about your story. I hope you are not naive enough to think
anything in software should have an ending.
The fact that you are "with me" on the argument that it should be in
the standard shows that you agree that
the language should change as times change.

Since you brought reasoning how do you logically say that the language
should have something it doesn't, and don't blame the language?
The reason I wanted, and apparently was crying over, a 64 bit int
only has a little to do with being a baby.
I am just trying to grab a value from a database, a value that is a 64
bit number. it's one variable in my program that I get and then do a
couple
computations on. Forgive me if I didn't want to use your precious
boost library and add an extra file to my project for 1 variable. The
point is that
the database is a pretty old database and I figured that if it was easy
for the database people to do years ago it should be cake today.
Adding a library is less
than cake. long long is a little closer to cake. It being a standard
and documented would be cake. I just want cake or as close to it as I
can get.

That being said I don't know why you posted. I thought "Good to hear"
was a positive notion.

Dec 7 '05 #18
On 7 Dec 2005 08:23:19 -0800, Ja**********@gm ail.com wrote in
comp.lang.c++:
unsigned long long a = 999999999999999 9999LLU; is the right way to do
it. If you don't say it's unsigned you get warnings because it's too
large.

That works fine for 64 bit numbers on 32 bit machine.


Except that there is no long long type, signed or unsigned, in
standard C++. It is standard in C since 1999, but an extension in
C++.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Dec 8 '05 #19
Jay <Co******@gmail .com> wrote:
the database is a pretty old database and I figured that if it was
easy for the database people to do years ago it should be cake today.


hahahaha. Tell me more about fixed point decimal arithmetic in C++ .
B.

Dec 8 '05 #20

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

Similar topics

11
3083
by: Tony Johansson | last post by:
Hello! I have some problem with STL function remove I have two classes called Handle which is a template class and Integer which is not a template class. The Integer class is just a wrapper class for a primitive int with some methods. I don't show the Integer class because it will not add any information to my problem. Main is using some STL function Now to my problem.
11
1833
by: nephish | last post by:
Hello there, i need a way to check to see if a certain value can be an integer. I have looked at is int(), but what is comming out is a string that may be an integer. i mean, it will be formatted as a string, but i need to know if it is possible to be expressed as an integer. like this var = some var passed to my script if var can be an integer :
21
4123
by: Frederick Gotham | last post by:
I set about trying to find a portable way to set the value of UCHAR_MAX. At first, I thought the following would work: #define UCHAR_MAX ~( (unsigned char)0 ) However, it didn't work for me. Could someone please explain to me what's going on? I would have thought that the following happens: (1) The literal, 0, whose type is int, gets converted to an unsigned char.
8
6559
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the second iteration it should return the number 5, and so on. But for some reason on the first iteration returns the expected results. Each subsequent iteration returns the number plus 1. In order words, when I run the program I am getting: 7, 6, 4, and...
1
3785
by: charles_gero | last post by:
Hi all, I had a question about the topics in the subject and posted to comp.std.c, but feel it may also be appropriate here. Please excuse this crosspost if it is in bad form. I have a question about whether or not I am interpreting a nuance of the standard correctly, and the implications of said nuance. The sections in the C99 standard (and possibly older standards) that I will reference are as follows (typed out hopefully to avoid...
7
30211
by: laura | last post by:
Hi, I have a variable of type double. I need to know if there is an integer number store there. How can I test that ? I also have a default precision for doing this operation. Many thanks, Laura
9
12617
by: jacob navia | last post by:
Hi I am incorporating 128 Bit integer code into lcc-win and it would be nice to have some code to test this feature. Has anyone here code that uses 128 bit integers? Thanks in advance P.S. This feature is now native in the 64 bit version, i.e.
12
3293
by: lithiumcat | last post by:
Hi, I bothered you a while back about storing integer values in void*. Now in a completely unrelated context, I'm trying to store pointer values in an integer type. So the basic question is, is it possible to convert a pointer into an integer, and then later (but on the same execution environment, ie the program has not exited, thus it's the same architecture, same compiler, same binary representations and so on) retrieve from the
14
5166
by: Default User | last post by:
Hi, If I have three 64 bit integers and I want to do this operation on them: x*y/z Lets say that what we are multiplying by (y) is offset by what we are dividing by (z) so that the final answer will fit in a 64-bit integer. Let me simplify it by using unsigned chars (8 bits):
9
5339
by: tsuyois | last post by:
Hi, I just signed in to this excellent network. I hope I could get some answers to many questions I have in writing C compilers. My first question is: Is "integer demotion" required in ANSI-C? Assumption: - CPU: 32-bit RISC (int = long = 4 bytes, short = 2 bytes, char = 1 byte)
0
8773
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6733
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
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
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2177
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.