Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Does your favorite C++ compiler support 64-bit integer types?

Reply
Thread Tools

Does your favorite C++ compiler support 64-bit integer types?

 
 
Matt
Guest
Posts: n/a
 
      04-13-2004
Please skip to the last paragraph if you are in a hurry.

Some of the integer variables in my application will need to hold values
bigger than 2^32-1.

Others won't need to be that big. Time and space efficiencies on
run-of-the-mill (read: 32 bit) microcomputers are important.

I want to use some layer of abstraction comparable to C99's stdint.h so
that my variable declarations specify the number of bits.

My app is to run on general-purpose hardware on Linux, Mac, BSD, and
Windows.

I am more interested in practical portability than in ISO standards.
Also it seems to be irrelevant whether the 64-bit type is long or long long.

Which C++ compilers do and which do not have 64-bit integer types? And
do they have something like stdint.h?

 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      04-13-2004
On Tue, 13 Apr 2004 21:19:04 GMT in comp.lang.c++, Matt
<(E-Mail Removed)> wrote,
>Which C++ compilers do and which do not have 64-bit integer types? And
>do they have something like stdint.h?


Digital Mars C++ http://www.digitalmars.com
has "long long" and stdint.h.

 
Reply With Quote
 
 
 
 
John Carson
Guest
Posts: n/a
 
      04-13-2004
"Matt" <(E-Mail Removed)> wrote in message
news:cPYec.1041$(E-Mail Removed)
> Please skip to the last paragraph if you are in a hurry.
>
> Some of the integer variables in my application will need to hold
> values bigger than 2^32-1.
>
> Others won't need to be that big. Time and space efficiencies on
> run-of-the-mill (read: 32 bit) microcomputers are important.
>
> I want to use some layer of abstraction comparable to C99's stdint.h
> so that my variable declarations specify the number of bits.
>
> My app is to run on general-purpose hardware on Linux, Mac, BSD, and
> Windows.
>
> I am more interested in practical portability than in ISO standards.
> Also it seems to be irrelevant whether the 64-bit type is long or
> long long.
>
> Which C++ compilers do and which do not have 64-bit integer types?
> And
> do they have something like stdint.h?


Microsofts has a 64 bit data type, though I think it is less efficient than
the 32 bit integer type. The various types (besides the usual int etc.) are
listed here.

http://msdn.microsoft.com/library/de...data_types.asp


--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

 
Reply With Quote
 
Matt
Guest
Posts: n/a
 
      04-13-2004
David Harmon wrote:
> On Tue, 13 Apr 2004 21:19:04 GMT in comp.lang.c++, Matt
> <(E-Mail Removed)> wrote,
>
>>Which C++ compilers do and which do not have 64-bit integer types? And
>>do they have something like stdint.h?

>
>
> Digital Mars C++ http://www.digitalmars.com
> has "long long" and stdint.h.
>


And its long long is 64 bits?

 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      04-13-2004
"Matt" <(E-Mail Removed)> wrote in message
news:cPYec.1041$(E-Mail Removed)...
> Please skip to the last paragraph if you are in a hurry.
>
> Some of the integer variables in my application will need to hold values
> bigger than 2^32-1.
>
> Others won't need to be that big. Time and space efficiencies on
> run-of-the-mill (read: 32 bit) microcomputers are important.
>
> I want to use some layer of abstraction comparable to C99's stdint.h so
> that my variable declarations specify the number of bits.



You can easily define your own class. I also assume that there must be some
third party free library out there provoding an 64-bit type.

Or you can use a system-specific type like __int64 in .NET.


> My app is to run on general-purpose hardware on Linux, Mac, BSD, and
> Windows.
>
> I am more interested in practical portability than in ISO standards.
> Also it seems to be irrelevant whether the 64-bit type is long or long

long.


There isn't long long in standard C++. Portability can be maintained by
using a typedef for built in system-specific types. For example you could
do:


typedef __int 64 Int64

// ...

and change the typedef when you move to another system. The general rule is
"isolate system dependencies in a small portion of the code". You can create
a header file called
system_dependencies.h or something.


>
> Which C++ compilers do and which do not have 64-bit integer types? And
> do they have something like stdint.h?



How many compilers exist out there? How many versions of them? The question
is meaningless. You can basically tell us what OS you are using. For Windows
a nice free port of GCC supporting Win32 API is mingw:

http://www.mingw.org/

If you want it integrated with an IDE you can download Dev-C++:
http://www.bloodshed.net/devcpp.html






Ioannis Vranos

 
Reply With Quote
 
Chuck McDevitt
Guest
Posts: n/a
 
      04-13-2004
In the Visual Studio 2005 tech preview Microsoft is giving out,
long long is supported and is the same as __int64.



 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      04-13-2004
On Tue, 13 Apr 2004 22:07:48 GMT in comp.lang.c++, Matt
<(E-Mail Removed)> wrote,
>David Harmon wrote:
>> On Tue, 13 Apr 2004 21:19:04 GMT in comp.lang.c++, Matt
>> <(E-Mail Removed)> wrote,
>>
>>>Which C++ compilers do and which do not have 64-bit integer types? And
>>>do they have something like stdint.h?

>>
>>
>> Digital Mars C++ http://www.digitalmars.com
>> has "long long" and stdint.h.
>>

>
>And its long long is 64 bits?


Yes. I thought I implied that. It would certainly violate expectations
if it was anything less.

Using free command line DMC++ with accompanying stlport library.
Program:

#include <iostream>
int main()
{
int j = 0;
long long int i = 0;
do {
i = (i << 1) + 1;
++j;
std::cout << j << " " << i << '\n';
} while (i > 0);
}

Output:

1 1
2 3
3 7
4 15
5 31
6 63
7 127
8 255
9 511
10 1023
11 2047
12 4095
13 8191
14 16383
15 32767
16 65535
17 131071
18 262143
19 524287
20 1048575
21 2097151
22 4194303
23 8388607
24 16777215
25 33554431
26 67108863
27 134217727
28 268435455
29 536870911
30 1073741823
31 2147483647
32 4294967295
33 8589934591
34 17179869183
35 34359738367
36 68719476735
37 137438953471
38 274877906943
39 549755813887
40 1099511627775
41 2199023255551
42 4398046511103
43 8796093022207
44 17592186044415
45 35184372088831
46 70368744177663
47 140737488355327
48 281474976710655
49 562949953421311
50 1125899906842623
51 2251799813685247
52 4503599627370495
53 9007199254740991
54 18014398509481983
55 36028797018963967
56 72057594037927935
57 144115188075855871
58 288230376151711743
59 576460752303423487
60 1152921504606846975
61 2305843009213693951
62 4611686018427387903
63 9223372036854775807
64 -1

 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      04-13-2004
Here is a brain teaser for anyone who might be interested.
The following numbers (in the second column) all end with the digit
1, 3, 5, or 7. It's obvious why they are all odd. Why can the last
digit never be 9, even if you extended the sequence?


On Tue, 13 Apr 2004 22:57:45 GMT in comp.lang.c++, David Harmon
<(E-Mail Removed)> wrote,
>Program:
>
>#include <iostream>
>int main()
>{
> int j = 0;
> long long int i = 0;
> do {
> i = (i << 1) + 1;
> ++j;
> std::cout << j << " " << i << '\n';
> } while (i > 0);
>}
>
>Output:
>
>1 1
>2 3
>3 7
>4 15
>5 31
>6 63
>7 127
>8 255
>9 511
>10 1023
>11 2047
>12 4095
>13 8191
>14 16383
>15 32767
>16 65535
>17 131071
>18 262143
>19 524287
>20 1048575
>21 2097151
>22 4194303
>23 8388607
>24 16777215
>25 33554431
>26 67108863
>27 134217727
>28 268435455
>29 536870911
>30 1073741823
>31 2147483647
>32 4294967295
>33 8589934591
>34 17179869183
>35 34359738367
>36 68719476735
>37 137438953471
>38 274877906943
>39 549755813887
>40 1099511627775
>41 2199023255551
>42 4398046511103
>43 8796093022207
>44 17592186044415
>45 35184372088831
>46 70368744177663
>47 140737488355327
>48 281474976710655
>49 562949953421311
>50 1125899906842623
>51 2251799813685247
>52 4503599627370495
>53 9007199254740991
>54 18014398509481983
>55 36028797018963967
>56 72057594037927935
>57 144115188075855871
>58 288230376151711743
>59 576460752303423487
>60 1152921504606846975
>61 2305843009213693951
>62 4611686018427387903
>63 9223372036854775807
>64 -1


 
Reply With Quote
 
John Carson
Guest
Posts: n/a
 
      04-14-2004
"David Harmon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> Here is a brain teaser for anyone who might be interested.
> The following numbers (in the second column) all end with the digit
> 1, 3, 5, or 7. It's obvious why they are all odd. Why can the last
> digit never be 9, even if you extended the sequence?


i = (i << 1) + 1;

translates to

i = i*2 +1;

This is a first order difference equation with solution (given the initial
condition)

i_n = 2^n - 1

where i_n is the nth term in the sequence and ^ denotes exponent.
(Alternatively, you are forming each successive number by left-shifting and
adding 1, which means that you have a binary number consisting solely of 1s.
Such numbers are of the form 2^n - 1.)

For a number to end in 9, we would need:

2^n - 1 == K*10 + 9

for some integers n and K. Adding 1 to both sides

2^n == K*10 + 10

or

2^n == (K+1)*10

Dividing both sides by 2:

2^(n-1) == (K+1)*5

We see that the left hand side has 2 as its only prime factor, whereas the
right hand side has 5 as a prime factor. By the unique prime factorisation
theorem, this is impossible if the left and right hand sides are equal. This
shows the equality is impossible. QED.


--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

 
Reply With Quote
 
Matt
Guest
Posts: n/a
 
      04-14-2004
David Harmon wrote:
> Here is a brain teaser for anyone who might be interested.
> The following numbers (in the second column) all end with the digit
> 1, 3, 5, or 7. It's obvious why they are all odd. Why can the last
> digit never be 9, even if you extended the sequence?


It would imply that some power of two is divisible by five.

 
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
Cast Your Vote For Your Favorite Movie right now. aasghar Digital Photography 0 06-16-2008 07:29 AM
Change a string to an integer, report an error if the string does not represent an integer? Randy Kramer Ruby 12 10-25-2007 09:56 PM
Does your C compiler support "//"? (was Re: using structures) Samuel Barber C Programming 382 08-25-2004 07:06 PM
Putting your Cell Phone Camera to good use - help fund your favorite charity David Blumenstein Digital Photography 2 08-04-2004 09:46 PM
will Synposys Design Compiler support division by two's power and integer rounding? walala VHDL 12 09-14-2003 03:49 PM



Advertisments