Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > 64 bit integer

Reply
Thread Tools

64 bit integer

 
 
mlimber
Guest
Posts: n/a
 
      12-07-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> unsigned long long a = 9999999999999999999LLU; 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

 
Reply With Quote
 
 
 
 
Clark S. Cox III
Guest
Posts: n/a
 
      12-07-2005
On 2005-12-07 11:23:19 -0500, (E-Mail Removed) said:

> unsigned long long a = 9999999999999999999LLU; 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
(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Greg
Guest
Posts: n/a
 
      12-07-2005

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 = 9999999999999999999;
>
> I am using g++ version 3.3.5(suse 9.3) and have tried both:
>
> unsigned long long test = 999999999999999999;
> and:
> uint64_t test = 9999999999999999999;
>
> 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 = 999999999999999999ULL;

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

 
Reply With Quote
 
Greg
Guest
Posts: n/a
 
      12-07-2005

mlimber wrote:
> (E-Mail Removed) wrote:
> > unsigned long long a = 9999999999999999999LLU; 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

 
Reply With Quote
 
Jay
Guest
Posts: n/a
 
      12-07-2005
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

 
Reply With Quote
 
Jay
Guest
Posts: n/a
 
      12-07-2005
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

 
Reply With Quote
 
Markus Moll
Guest
Posts: n/a
 
      12-07-2005
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

 
Reply With Quote
 
Jay
Guest
Posts: n/a
 
      12-07-2005
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.

 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      12-08-2005
On 7 Dec 2005 08:23:19 -0800, (E-Mail Removed) wrote in
comp.lang.c++:

> unsigned long long a = 9999999999999999999LLU; 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.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
 
Reply With Quote
 
Bronek Kozicki
Guest
Posts: n/a
 
      12-08-2005
Jay <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
64-bit and 128 bit integer as a combination of 32-bits xyz C Programming 2 08-02-2010 10:21 PM
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
How to use 64 bit integer in 16 Bit Dos ? Imayam C Programming 3 06-15-2006 12:46 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments