473,396 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

__int64 vs. long long

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
Jul 19 '05 #1
8 100203
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.

Jul 19 '05 #2
> 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

Jul 19 '05 #3

"Tim Clacy" <no*******@nospamphaseone.nospamdk> wrote in message news:3f*********************@news.dk.uu.net...
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.
Jul 19 '05 #4
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
Jul 19 '05 #5

"Tim Clacy" <no*******@nospamphaseone.nospamdk> wrote in message news:3f*********************@news.dk.uu.net...
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.
Jul 19 '05 #6
On Mon, 10 Nov 2003 11:59:30 +0100, "Tim Clacy"
<no*******@nospamphaseone.nospamdk> 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
Jul 19 '05 #7
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.

Jul 19 '05 #8
> 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


Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

88
by: Matt | last post by:
Hi folks. Can you help with some questions? I gather that some types supported by g++ are nonstandard but have been proposed as standards. Are the long long and unsigned long long types still...
29
by: Richard A. Huebner | last post by:
Is the unsigned long long primitive data type supported in ANSI standard C? I've tried using it a couple of times in standard C, but to no avail. I'm using both MS VIsual C++ 6, as well as the...
8
by: Keoncheol Shin | last post by:
Hi to all! I wonder how gcc treat 64bit integer type(long long int) internally in 32bit machine. If possible, please tell me the related webpage. Thank you.
8
by: silangdon | last post by:
Hi, I've need a function to print a long long to the console and needs to run under Win32 and some unknown variant of *Nix (a client's unspecified server) in Win32 I've got _int64 iVal...
12
by: __frank__ | last post by:
Which format I have to use in scanf, to format a long long int (64bits int __int64 in MS VC++). Thanks in advance
21
by: Charles Sullivan | last post by:
I maintain/enhance some inherited FOSS software in C which has compiler options for quite a few different Unix-like operating systems, many of which I've never even heard of. It would be...
21
by: Sebastian Faust | last post by:
Hi, Unfortunately, I don't find lots of information on this warning. It occurs if I compile with -pedantic but I am not sure how I can resolve this problem. Do you have an idea? The following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.