Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > __int64 vs. long long

Reply
Thread Tools

__int64 vs. long long

 
 
Tim Clacy
Guest
Posts: n/a
 
      11-10-2003
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


 
Reply With Quote
 
 
 
 
Peter van Merkerk
Guest
Posts: n/a
 
      11-10-2003
> 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

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl



 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      11-10-2003
Tim Clacy wrote:

> 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.

 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      11-10-2003

"Tim Clacy" <(E-Mail Removed)> wrote in message news:3faf6f93$0$270$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Tim Clacy
Guest
Posts: n/a
 
      11-10-2003
Tim Clacy wrote:
> 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


 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      11-10-2003

"Tim Clacy" <(E-Mail Removed)> wrote in message news:3faf9a02$0$269$(E-Mail Removed)...

> 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.


 
Reply With Quote
 
tom_usenet
Guest
Posts: n/a
 
      11-10-2003
On Mon, 10 Nov 2003 11:59:30 +0100, "Tim Clacy"
<(E-Mail Removed)> wrote:

>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
 
Reply With Quote
 
Peter van Merkerk
Guest
Posts: n/a
 
      11-10-2003
> 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.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl








 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      11-10-2003
Tim Clacy wrote:

> Tim Clacy wrote:
>> 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?


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.

 
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
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
Why different sizes (with unions) when __int64 used??? JR C++ 3 02-05-2004 03:31 PM
unsigned __int64 overflow problem Vivi C++ 2 08-25-2003 06:09 AM
SWIG and __int64 Matt Whelan Python 2 08-15-2003 08:40 PM
Re: Different results if compared as double or __int64? John Tsiombikas (Nuclear / the Lab) C++ 1 06-30-2003 02:31 PM



Advertisments