__int64 vs. long long

T

Tim Clacy

How is a 64 bit type defined in strict C++?


It seems C has support for 'long long' since C99, but not so for C++?
Looking through one compiler vendor's standard library headers has clouded
the issue somewhat; it uses __int64 in some places (with a comment about
strict) but freely uses 'long long' in other places. In any case, these
standard library headers are supposed to be 'standard' w.r.t. C and C++
aren't they? How can a standard library header use 'long long' if 'long
long' isn't standard in C++?

C++ luminaries, please illuminate...


Tim
 
P

Peter van Merkerk

How is a 64 bit type defined in strict C++?

At htis moment there is no standard integer type that is guaranteed to
be 64-bits long in C++. __int64 and long long are non-standard
extensions. Neither one is guaranteed to be supported by all C++
compilers.
It seems C has support for 'long long' since C99, but not so for C++?
Looking through one compiler vendor's standard library headers has clouded
the issue somewhat; it uses __int64 in some places (with a comment about
strict) but freely uses 'long long' in other places.

That is because it is not standardized (yet)
In any case, these
standard library headers are supposed to be 'standard' w.r.t. C and C++
aren't they?

No, only the interface of the standard library is defined in the
standard, not the implementation. The implementers are free to implement
the standard library the way the like as long as does it not violate the
requirements defined in the standard.
How can a standard library header use 'long long' if 'long
long' isn't standard in C++?

The C++ standard does not mandate the standard library to use 'long
long' datatypes. If the implementer decides to use non-standard
datatypes it simply means that that implementation of the standard
library cannot be used on compilers that doesn't support those types. As
long as the library user sticks with the definitions defined in the
standard, he or she shouldn't care whether or not the standard library
implementation he or she is using uses non-standard datatypes.

As long as 64-bits integers are not supported by the C++ standard it is
advisable to use typedefs for the 64-bits integer types, e.g.:

#if defined(COMPILER_1)
typedef long long long64;
#elif defined(COMPILER_2)
typedef __int64 long64;
#else
#error This compiler is not supported.
#endif
 
R

Rolf Magnus

Tim said:
How is a 64 bit type defined in strict C++?

Any built-in type may be 64 bit, but none is required to.
It seems C has support for 'long long' since C99, but not so for C++?

Right. C++ is based on C89 (it came out in 98, so it couldn't be based
on C99) and didn't get an additional type that must be at least 64bit.
Looking through one compiler vendor's standard library headers has
clouded the issue somewhat; it uses __int64 in some places (with a
comment about strict) but freely uses 'long long' in other places. In
any case, these standard library headers are supposed to be 'standard'
w.r.t. C and C++ aren't they?

They can themselves use whatever they want.
How can a standard library header use 'long long' if 'long long' isn't
standard in C++?

The standard library is not required to be implemnented in pure standard
C++. It can use any compiler specific extensions it wants as long as
the headers provide exactly the interface that the standard requires.
 
R

Ron Natalie

Tim Clacy said:
How is a 64 bit type defined in strict C++?

It isn't.
It seems C has support for 'long long' since C99, but not so for C++?

Because the C++ standard predates the C99 standard by a year.
it uses __int64 in some places

__int64 is a implementation extension by some compilers (notably Visual C++).
with a comment about strict) but freely uses 'long long' in other places. I

Comments where? Uses where? C++ doesn't have any clue about either
__int64 or long long.
 
T

Tim Clacy

Tim said:
How is a 64 bit type defined in strict C++?


It seems C has support for 'long long' since C99, but not so for C++?
Looking through one compiler vendor's standard library headers has
clouded the issue somewhat; it uses __int64 in some places (with a
comment about strict) but freely uses 'long long' in other places. In
any case, these standard library headers are supposed to be
'standard' w.r.t. C and C++ aren't they? How can a standard library
header use 'long long' if 'long long' isn't standard in C++?

C++ luminaries, please illuminate...


Tim

Hmm, first let me say thanks for shedding some light.

Now, at the risk of being flayed alive, why does C have a standard 64 bit
type but C++ doesn't? Who's leading who here? It seems that the C++ standard
to which most of you refer is dated 5 yeasr a go... which is the software
equivalent of a geological era. I've been using C++ since Microsoft C 7
which must be, what 1990 (feels like a geological era a go now)? Considering
that we're on the verge of using 64-bit machines, doesn't the lack of a
standard 64 bit type in C++ suggest that something's rotten in Denmark?
What's wrong here; the language or the standards bodies?


Tim
 
R

Ron Natalie

Tim Clacy said:
Now, at the risk of being flayed alive, why does C have a standard 64 bit

C doesn't have a standard 64 bit type. It has a type that has to be at least
64 bits.
type but C++ doesn't?

Because C didn't have one at the time and nobody felt strongly that C++ needed one.
It seems that the C++ standard
to which most of you refer is dated 5 yeasr a go...

And the C standard is 4 years old. And the one before that was 15 years.
Considering
that we're on the verge of using 64-bit machines, doesn't the lack of a
standard 64 bit type in C++

In general there are NO STANDARD TYPE SIZES., Nothing prohibits
long from being 64. I worked on a 64 bit mainframe that had 64 bit ints.
 
T

tom_usenet

How is a 64 bit type defined in strict C++?

char, short, int and/or long my be 64 bits. In practice they usually
aren't, but they might be on e.g. a 64-bit DSP chip (if such a think
exists).

Sadly long and int are usually both 32 bits, which is silly. For
platforms where int is 32 bits, it is a shame that long isn't 64 bits
- I don't know why it isn't.
It seems C has support for 'long long' since C99, but not so for C++?

Yes. But long long isn't necessarily 64 bits (although I think it is
at least 64 bits).
Looking through one compiler vendor's standard library headers has clouded
the issue somewhat; it uses __int64 in some places (with a comment about
strict) but freely uses 'long long' in other places. In any case, these
standard library headers are supposed to be 'standard' w.r.t. C and C++
aren't they? How can a standard library header use 'long long' if 'long
long' isn't standard in C++?

As a conforming extension.

Tom
 
P

Peter van Merkerk

Hmm, first let me say thanks for shedding some light.
Now, at the risk of being flayed alive, why does C have a standard 64 bit
type but C++ doesn't?

Ron Natalie already answered that question; the C++ standard predates
the C99 standard by a year.
Who's leading who here?

The latest C standard is more recent. It is unsure if all the additions
made to the C language will also be included in the next revision of the
C++ standard. Though I see no reason why a 64-bit integer support
wouldn't be in the next revision of the C++ standard.
It seems that the C++ standard
to which most of you refer is dated 5 yeasr a go... which is the software
equivalent of a geological era.

The latest C standard is from 4 years ago, the difference is not that
big to me.
I've been using C++ since Microsoft C 7
which must be, what 1990 (feels like a geological era a go now)?

Unfortunately C++ wasn't standardized at that time.
Considering
that we're on the verge of using 64-bit machines, doesn't the lack of a
standard 64 bit type in C++ suggest that something's rotten in Denmark?
What's wrong here; the language or the standards bodies?

Neither. As far as the language is concerned there is no fundamental
reason why a 64-bit integer couldn't be added to C++ (the fact that many
compilers already support this, proves my point). As far as the standard
is concerned keep in mind that the previous C standard was finalized in
1989, i.e. it took about 10 years for the second revision to arrive.
Only recently (five years after the C++ standard was finalized) C++
compilers have appeared on the market that are fully compliant or at
least very close to being compliant with the C++ standard. Considering
that, it doesn't make sense to update the standard every other year. If
a standard becomes a moving target, it defeats the purpose of having a
standard in the first place as there will be no products to support the
standard. The standardization comitees have find a compromize between
the standard on one side being stable enough be able to serve as a
reference point, and on the other side being updated frequently enough
to prevent it from becoming obsolete.

That being said I would like to see some of the C99 additions in the C++
standard as well, sooner rather than later.
 
R

Rolf Magnus

Tim said:
Hmm, first let me say thanks for shedding some light.

Now, at the risk of being flayed alive, why does C have a standard 64
bit type but C++ doesn't?

Because C++ was standardized one year before the new version of C.
Who's leading who here? It seems that the C++ standard to which most
of you refer is dated 5 yeasr a go... which is the software equivalent
of a geological era.

C++ is an international standard. If it changes every year, it's useless
as a standard. It must be stable for several years to be really useful
as a standard. Also, changes need to be thought about very carefully,
so it needs quite a lot of time to introduce them.
I've been using C++ since Microsoft C 7 which must be, what 1990
(feels like a geological era a go now)? Considering that we're on the
verge of using 64-bit machines, doesn't the lack of a standard 64 bit
type in C++ suggest that something's rotten in Denmark?

There is no standard x-bit (for any value of x) type at all, neither in
C, nor in C++, and never has been. The different types only have
requirements about the minimum range they have to support (which
implies minimum number of bits they have to be wide), but it's possible
to write a standard compliant C++ compiler on which char, short, int
and long all are 64bit wide. And in fact, on most 64bit machines, long
is 64bit AFAIK.
What's wrong here; the language or the standards bodies?

Your assumptions about the language are.
 

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,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top