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

P

PlasmaDragon

Peter van Merkerk said:
The Borland and Microsoft C++ compilers have the __int64 type and if I
remember correctly GCC has the long long type.

GCC also supports __int64. I think MSVC++ may support long long int,
and, if I am not hallucinating, something called "hyper int", which is
also 64 bits long.
 
B

Bill Seurer

Nick said:
gcc isn't a platform - it's just a compiler.
The size of long and long long varies with the target processor.

The compiler determines the size of long and long long, not the target
processor. The target processor might limit the choices of what sizes
long and long long could be, though.
 
N

Nick Hounsome

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

GCC also supports __int64. I think MSVC++ may support long long int,
and, if I am not hallucinating, something called "hyper int", which is
also 64 bits long.[/QUOTE]

GCC does NOT support __int64 on processors that don't support 64 bit ints.
 
N

Nick Hounsome

Bill Seurer said:
The compiler determines the size of long and long long, not the target
processor. The target processor might limit the choices of what sizes
long and long long could be, though.

No - the compiler is configured for the processor.
If the processor does not support 64 bit then the compiler will not normally
invent code to emulate it.
Thus if you port gcc to a processor without 64 support __int64 will not
work.
True it may well allow you to use long long but this will not be 64 bits and
will almost certainly be the
same size as long so there is no point in using it.
As a general principle it is rarely correct to just use the biggest int
available in your code and hope that
it has enough bits.
 
I

Ioannis Vranos

Nick Hounsome said:
No - the compiler is configured for the processor.
If the processor does not support 64 bit then the compiler will not normally
invent code to emulate it.
Thus if you port gcc to a processor without 64 support __int64 will not
work.
True it may well allow you to use long long but this will not be 64 bits and
will almost certainly be the
same size as long so there is no point in using it.
As a general principle it is rarely correct to just use the biggest int
available in your code and hope that
it has enough bits.


Then how .NET (and i assume Win32) has an __int64 type and compilers like
the VC++ one support it? And it *is* (behaves) as an 64 bit int.






Ioannis Vranos
 
R

Rob Williscroft

Ioannis Vranos wrote in in
comp.lang.c++:

But isn't long long the C type required to be at least 64 bits. i.e.
a long long type less than 64 bits isn't supporting any standard
and is simply useles.
Then how .NET (and i assume Win32) has an __int64 type and compilers
like the VC++ one support it? And it *is* (behaves) as an 64 bit int.

The same way 16 bit DOS/windows compilers (pre 386/32 bit) supported
32 bit long, by emulating it with 2 * 32 bit values.

BTW I've come across 1 compiler (I think a borland variant) that
had a __in64 type that would indeed hold 64 bit values, but I
had real problems with using them like an int (+-/*% etc).


Rob.
 
J

Jerry Coffin

[ ... ]
GCC does NOT support __int64 on processors that don't support 64 bit ints.

I'm not at all convinced that _any_ version of gcc supports __int64.

Most recent versions of gcc support long long, and it works nicely on
32-bit processors, with the compiler generating sequences of 32-bit
instructions to carry out 64-bit operations.

AFAIK, __int64 is mostly a Microsoft thing, and it's supported
primarily on 32-bit processors as well. In fact, I'm not aware of
their compiler generating 64-bit instructions for __int64 operations,
even on processors such as AMD's that support them (though I'd expect
to see it in some future version of the processor). At one time, when
they produced a processor for the Alpha, that used 64-bit instructions
for __int64, but that's been gone for quite some time.
Later,
Jerry.
 
A

Asfand Yar Qazi

In summary: the question is:
And what? I was answering the question "Does anyone know of any
platform where long < 64 bits and long long >= 64 bits".

I believe that x86-32 gcc has long of 32-bits (32 < 64) and long long
64-bits (64 >= 64).
 
D

David Harmon

On Fri, 16 Apr 2004 07:36:24 +0100 in comp.lang.c++, "Nick Hounsome"
A compiler, libraries AND processor

You just made that up.

And of the three, it is the compiler that determines the sizes of the
integral types that it provides to you.
 
D

David Harmon

On Fri, 16 Apr 2004 07:41:16 +0100 in comp.lang.c++, "Nick Hounsome"
No - the compiler is configured for the processor.
If the processor does not support 64 bit then the compiler will not normally
invent code to emulate it.
Thus if you port gcc to a processor without 64 support __int64 will not
work.

However, when Walter Bright writes Digital Mars C++
(http://www.digitalmars.com) for a processor with no 64bit
registers and no 64 bit arithmetic, __int64 does work and is 64 bits.

Any compiler that uses less than 64 bits for __int64 is just broken.
 
I

Ioannis Vranos

Jerry Coffin said:
"Nick Hounsome" <[email protected]> wrote in message
[ ... ]
GCC does NOT support __int64 on processors that don't support 64 bit
ints.

I'm not at all convinced that _any_ version of gcc supports __int64.

Most recent versions of gcc support long long, and it works nicely on
32-bit processors, with the compiler generating sequences of 32-bit
instructions to carry out 64-bit operations.

AFAIK, __int64 is mostly a Microsoft thing, and it's supported
primarily on 32-bit processors as well. In fact, I'm not aware of
their compiler generating 64-bit instructions for __int64 operations,
even on processors such as AMD's that support them (though I'd expect
to see it in some future version of the processor). At one time, when
they produced a processor for the Alpha, that used 64-bit instructions
for __int64, but that's been gone for quite some time.


DJGPP which is a GCC port for Windows, supports long long as an 64-bit type.


#include <stdio.h>
#include <limits.h>

int main()
{
printf("LLONG_MAX: %lld\nLONG_MAX: %ld\n", LLONG_MAX, LONG_MAX);

}



C:\c>gcc -std=c99 -pedantic-errors temp.c -o temp.exe

C:\c>temp
LLONG_MAX: 9223372036854775807
LONG_MAX: 2147483647

C:\c>






Ioannis Vranos
 
R

red floyd

David said:
On Fri, 16 Apr 2004 07:41:16 +0100 in comp.lang.c++, "Nick Hounsome"



However, when Walter Bright writes Digital Mars C++
(http://www.digitalmars.com) for a processor with no 64bit
registers and no 64 bit arithmetic, __int64 does work and is 64 bits.

Any compiler that uses less than 64 bits for __int64 is just broken.

Since __int64 is not part of the standard, a compiler is free to use whatever
the hell it wants for that.
 
M

Matt

David said:
On Fri, 16 Apr 2004 07:36:24 +0100 in comp.lang.c++, "Nick Hounsome"



You just made that up.

And of the three, it is the compiler that determines the sizes of the
integral types that it provides to you.

I thank you and comp.lang.c++ thanks you.
 
J

Jack Walker

Ioannis Vranos said:
Then how .NET (and i assume Win32) has an __int64 type and compilers like
the VC++ one support it? And it *is* (behaves) as an 64 bit int.

Well .NET is a virtual processor system like the JVM so every type it
supports is emulated in software.

Jack Walker
 
J

Jack Walker

Nils Petter Vaskinn said:
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

Here is a possible challange: Write a template meta program to define
the afforementioned type.

Jack Walker
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top