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

M

Matt

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?
 
J

John Carson

Matt said:
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/default.asp?url=/library/en-us/win64/win64/the_new_data_types.asp
 
I

Ioannis Vranos

Matt said:
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
 
C

Chuck McDevitt

In the Visual Studio 2005 tech preview Microsoft is giving out,
long long is supported and is the same as __int64.
 
D

David Harmon

On Tue, 13 Apr 2004 21:19:04 GMT in comp.lang.c++, Matt



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

And its long long is 64 bits?[/QUOTE]

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
 
D

David Harmon

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
 
J

John Carson

David Harmon said:
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.
 
M

Matt

David said:
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.
 
D

David Harmon

On Wed, 14 Apr 2004 11:04:03 +1000 in comp.lang.c++, "John Carson"
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.

Yep.
 
N

Nick Hounsome

Matt said:
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?

It is not a question of compilers.
If the platform does not have 64 bit operations the compiler for it will not
have 64 bit types even if it supports long long. (ie long long will be less
than 64 bits).
If it does have 64 bit operations then the type will almost certainly be
long.
I would only expect long long to differ from long if the machine has either:
1. support for 32, 64 and 128 bit
2. A 'natural' int size of 16 + support for 32 and 64 bit
I don't know of any common processor that fits either of these
descriptions - in the first case long would be enough for you anyway and I
doubt that the second ever existed.

In summary: the question is:
Does anyone know of any platform where long < 64 bits and long long >= 64
bits?
 
J

John Carson

Nick Hounsome said:
It is not a question of compilers.

Actually, it is since compilers can extend (or restrict) what is available
on a given system.
If the platform does not have 64 bit operations the compiler for it
will not have 64 bit types even if it supports long long. (ie long
long will be less than 64 bits).
If it does have 64 bit operations then the type will almost certainly
be long.
I would only expect long long to differ from long if the machine has
either:
1. support for 32, 64 and 128 bit
2. A 'natural' int size of 16 + support for 32 and 64 bit
I don't know of any common processor that fits either of these
descriptions - in the first case long would be enough for you anyway
and I doubt that the second ever existed.

In summary: the question is:
Does anyone know of any platform where long < 64 bits and long long


On VC++ for standard Intel Pentium (or 486) processors running Windows, long
is 32 bits and long long is 64 bits.

http://msdn.microsoft.com/library/d...-us/vclang/html/_langref_data_type_ranges.asp
 
N

Nils Petter Vaskinn

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?

Something like this may work if you really want it portable:

#if <some magic to detect 64bit long>
typedef long my64bit_t;
#elif <some magic to detect 64 bit long long>
typedef long long my64bit_t;
#elif <some magic to detect 64 bit int>
typedef int my64bit_t;
#else
class my64bit_t {
public:
my64bit_t();
my64bit_t(long x);
my64bit_t(unsigned char* bytes);
...

my64bit_t operator +(my64bit_t a, my64bit_t b);

...
my64bit_t operator << (my64bit_t a, int n);
...
private:
unsigned char data[8]; /* assuming 8 bit bytes */
};

/* or perhaps just #include <bigintlibrary.h> and then a single
typedef */
#endif
 
P

Peter van Merkerk

Which C++ compilers do and which do not have 64-bit integer types?

The Borland and Microsoft C++ compilers have the __int64 type and if I
remember correctly GCC has the long long type.
 
M

Matt

Nick said:
It is not a question of compilers.
If the platform does not have 64 bit operations the compiler for it will not
have 64 bit types even if it supports long long. (ie long long will be less
than 64 bits).
If it does have 64 bit operations then the type will almost certainly be
long.
I would only expect long long to differ from long if the machine has either:
1. support for 32, 64 and 128 bit
2. A 'natural' int size of 16 + support for 32 and 64 bit
I don't know of any common processor that fits either of these
descriptions - in the first case long would be enough for you anyway and I
doubt that the second ever existed.

In summary: the question is:
Does anyone know of any platform where long < 64 bits and long long >= 64
bits?

A person is lucky when he has a real expert to help him ask the right
question.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top