* int64_t == long long
@ 2008-07-01 19:18 Yang Zhang
2008-07-01 19:33 ` John Love-Jensen
0 siblings, 1 reply; 11+ messages in thread
From: Yang Zhang @ 2008-07-01 19:18 UTC (permalink / raw)
To: gcc-help
Hi, why isn't int64_t == long long at least on 64-bit x86 Linux?
http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/Long-Long.html
says that these are *at least* 64 bits. How do I tell what type this
actually is? And are literals ending with LL always long long?
Thanks in advance for any answers!
$ uname -a
Linux yang-xps410 2.6.24-19-generic #1 SMP Wed Jun 18 14:15:37 UTC 2008
x86_64 GNU/Linux
$ cat longlongint.cc
#include <iostream>
#include <string>
using namespace std;
void f(int64_t x) { cout << x << endl; }
void f(int32_t x) { cout << x << endl; }
void f(int16_t x) { cout << x << endl; }
void f(int8_t x) { cout << x << endl; }
void f(double x) { cout << x << endl; }
void f(float x) { cout << x << endl; }
void f(string& x) { cout << x << endl; }
int
main()
{
long long int x = 32;
f(x);
int64_t y = 32;
f(y);
f(0LL);
return 0;
}
$ g++ -pedantic -Wall -Wextra longlongint.cc
longlongint.cc:21:5: warning: use of C99 long long integer constant
longlongint.cc: In function âint main()â:
longlongint.cc:17: error: ISO C++ does not support âlong longâ
longlongint.cc:18: error: call of overloaded âf(long long int&)â is
ambiguous
longlongint.cc:6: note: candidates are: void f(int64_t)
longlongint.cc:7: note: void f(int32_t)
longlongint.cc:8: note: void f(int16_t)
longlongint.cc:9: note: void f(int8_t)
longlongint.cc:10: note: void f(double)
longlongint.cc:11: note: void f(float)
longlongint.cc:21: error: call of overloaded âf(long long int)â is ambiguous
longlongint.cc:6: note: candidates are: void f(int64_t)
longlongint.cc:7: note: void f(int32_t)
longlongint.cc:8: note: void f(int16_t)
longlongint.cc:9: note: void f(int8_t)
longlongint.cc:10: note: void f(double)
longlongint.cc:11: note: void f(float)
--
Yang Zhang
http://www.mit.edu/~y_z/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-01 19:18 int64_t == long long Yang Zhang
@ 2008-07-01 19:33 ` John Love-Jensen
2008-07-01 20:02 ` Yang Zhang
2008-07-16 0:31 ` Yang Zhang
0 siblings, 2 replies; 11+ messages in thread
From: John Love-Jensen @ 2008-07-01 19:33 UTC (permalink / raw)
To: Yang Zhang, GCC-help
On 7/1/08 2:17 PM, "Yang Zhang" <yanghatespam@gmail.com> wrote:
> Hi, why isn't int64_t == long long at least on 64-bit x86 Linux?
Because int64_t should be 64-bit, but long long could be 64-bit or larger.
#include <stdint.h> // from C99
#include <climits>
cout << (sizeof(int64_t) * CHAR_BIT) << endl;
cout << (sizeof(long long) * CHAR_BIT) << endl;
You can also do this:
#include <stdint.h> // from C99
#include <typeinfo>
cout << typeid(int64_t).name() << endl;
cout << typeid(long long).name() << endl;
> How do I tell what type this actually is?
typeid
> And are literals ending with LL always long long?
Yes, that's what the LL suffix means.
So the literal integer numerics are:
'A'
L'A'
65
65L
65LL
65U
65UL
65ULL
Keep in mind the portability issues surrounding use of long long, LL, and
ULL. You may want to use the <stdint.h> INT64_C and UINT64_C macros to
construct your numeric literals.
INT64_C(65)
UINT64_C(65)
HTH,
--Eljay
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-01 19:33 ` John Love-Jensen
@ 2008-07-01 20:02 ` Yang Zhang
2008-07-01 20:19 ` Wesley Smith
2008-07-01 23:47 ` John Love-Jensen
2008-07-16 0:31 ` Yang Zhang
1 sibling, 2 replies; 11+ messages in thread
From: Yang Zhang @ 2008-07-01 20:02 UTC (permalink / raw)
To: John Love-Jensen; +Cc: GCC-help
John Love-Jensen wrote:
> On 7/1/08 2:17 PM, "Yang Zhang" <yanghatespam@gmail.com> wrote:
>
>> Hi, why isn't int64_t == long long at least on 64-bit x86 Linux?
>
> Because int64_t should be 64-bit, but long long could be 64-bit or larger.
>
> #include <stdint.h> // from C99
> #include <climits>
>
> cout << (sizeof(int64_t) * CHAR_BIT) << endl;
> cout << (sizeof(long long) * CHAR_BIT) << endl;
cout << sizeof(int64_t) << endl;
cout << sizeof(long long) << endl;
print:
8
8
>
> You can also do this:
>
> #include <stdint.h> // from C99
> #include <typeinfo>
>
> cout << typeid(int64_t).name() << endl;
> cout << typeid(long long).name() << endl;
This prints:
l
x
What does this mean? (typeid(string).name() prints "Ss")
--
Yang Zhang
http://www.mit.edu/~y_z/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-01 20:02 ` Yang Zhang
@ 2008-07-01 20:19 ` Wesley Smith
2008-07-01 20:26 ` Yang Zhang
2008-07-01 23:47 ` John Love-Jensen
1 sibling, 1 reply; 11+ messages in thread
From: Wesley Smith @ 2008-07-01 20:19 UTC (permalink / raw)
To: Yang Zhang; +Cc: John Love-Jensen, GCC-help
> cout << sizeof(int64_t) << endl;
> cout << sizeof(long long) << endl;
>
> print:
>
> 8
> 8
8*8 = 64
sizeof reports the # of bytes, not bits.
wes
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-01 20:19 ` Wesley Smith
@ 2008-07-01 20:26 ` Yang Zhang
0 siblings, 0 replies; 11+ messages in thread
From: Yang Zhang @ 2008-07-01 20:26 UTC (permalink / raw)
To: Wesley Smith; +Cc: John Love-Jensen, GCC-help
Wesley Smith wrote:
>> cout << sizeof(int64_t) << endl;
>> cout << sizeof(long long) << endl;
>>
>> print:
>>
>> 8
>> 8
>
>
> 8*8 = 64
>
> sizeof reports the # of bytes, not bits.
> wes
Thanks, I knew that. I was just confused why they weren't then being
treated as the same type.
--
Yang Zhang
http://www.mit.edu/~y_z/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-01 20:02 ` Yang Zhang
2008-07-01 20:19 ` Wesley Smith
@ 2008-07-01 23:47 ` John Love-Jensen
2008-07-02 4:50 ` Yang Zhang
1 sibling, 1 reply; 11+ messages in thread
From: John Love-Jensen @ 2008-07-01 23:47 UTC (permalink / raw)
To: Yang Zhang; +Cc: GCC-help
Hi Yang Zhang,
>> cout << typeid(int64_t).name() << endl;
>> cout << typeid(long long).name() << endl;
>
> This prints:
>
> l
> x
>
> What does this mean?
This means that they are not the same type.
HTH,
--Eljay
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-01 23:47 ` John Love-Jensen
@ 2008-07-02 4:50 ` Yang Zhang
2008-07-02 5:09 ` John Love-Jensen
2008-07-16 20:37 ` Philipp Thomas
0 siblings, 2 replies; 11+ messages in thread
From: Yang Zhang @ 2008-07-02 4:50 UTC (permalink / raw)
To: John Love-Jensen; +Cc: GCC-help
John Love-Jensen wrote:
> Hi Yang Zhang,
>
>>> cout << typeid(int64_t).name() << endl;
>>> cout << typeid(long long).name() << endl;
>> This prints:
>>
>> l
>> x
>>
>> What does this mean?
>
> This means that they are not the same type.
>
> HTH,
> --Eljay
>
You're right, of course, and I knew they were different already, without
needing to see the above output. I just wasn't sure if that was the
correct/expected output (I was assuming I'd get a more human-friendly name).
Steering this thread back on track: I'm still not sure why these are
different. So far, I know that both long long and int64_t are 64-bit
signed integral types. They still don't have to actually be the same
type, but I was hoping someone would be able to explain things to a bit
more depth (e.g. rationale).
--
Yang Zhang
http://www.mit.edu/~y_z/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-02 4:50 ` Yang Zhang
@ 2008-07-02 5:09 ` John Love-Jensen
2008-07-02 5:30 ` Yang Zhang
2008-07-16 20:37 ` Philipp Thomas
1 sibling, 1 reply; 11+ messages in thread
From: John Love-Jensen @ 2008-07-02 5:09 UTC (permalink / raw)
To: Yang Zhang; +Cc: GCC-help
Hi Yang Zhang,
My guess (purely speculative, not authoritative) is that on your platform, a
long int is 64-bit, and a long long is 64-bit. Assuming that guess is
correct, since long int is 64-bit *AND* long int is part of the C99 standard
the stdint.h used long int to be the alias for int64_t. Whereas long long
is a compiler extension*, so the long int was preferential to long long.
Sincerely,
--Eljay
* Is long long still a compiler extension for C99? I don't use C99.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-02 5:09 ` John Love-Jensen
@ 2008-07-02 5:30 ` Yang Zhang
0 siblings, 0 replies; 11+ messages in thread
From: Yang Zhang @ 2008-07-02 5:30 UTC (permalink / raw)
To: John Love-Jensen; +Cc: GCC-help
John Love-Jensen wrote:
> Hi Yang Zhang,
>
> My guess (purely speculative, not authoritative) is that on your platform, a
> long int is 64-bit, and a long long is 64-bit. Assuming that guess is
> correct, since long int is 64-bit *AND* long int is part of the C99 standard
> the stdint.h used long int to be the alias for int64_t. Whereas long long
> is a compiler extension*, so the long int was preferential to long long.
>
> Sincerely,
> --Eljay
>
> * Is long long still a compiler extension for C99? I don't use C99.
>
Hmm, you're right. So far, I believe:
On 64-bit:
??????? == long long int, aka long long
int64_t == long int, aka long
int32_t == int
On 32-bit:
int64_t == long long int, aka long long
int32_t == long int, aka long
int32_t == int
The mystery deepens.
(And I don't know about the C99 story.)
--
Yang Zhang
http://www.mit.edu/~y_z/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-01 19:33 ` John Love-Jensen
2008-07-01 20:02 ` Yang Zhang
@ 2008-07-16 0:31 ` Yang Zhang
1 sibling, 0 replies; 11+ messages in thread
From: Yang Zhang @ 2008-07-16 0:31 UTC (permalink / raw)
To: John Love-Jensen; +Cc: GCC-help
John Love-Jensen wrote:
> Keep in mind the portability issues surrounding use of long long, LL, and
> ULL. You may want to use the <stdint.h> INT64_C and UINT64_C macros to
> construct your numeric literals.
>
> INT64_C(65)
> UINT64_C(65)
I'm using gcc 4.2.3 and this doesn't compile (INT64_C doesn't exist).
#include <stdint.h>
#include <stdio.h>
int
main()
{
printf("%lld\n", INT64_C(0));
return 0;
}
--
Yang Zhang
http://www.mit.edu/~y_z/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: int64_t == long long
2008-07-02 4:50 ` Yang Zhang
2008-07-02 5:09 ` John Love-Jensen
@ 2008-07-16 20:37 ` Philipp Thomas
1 sibling, 0 replies; 11+ messages in thread
From: Philipp Thomas @ 2008-07-16 20:37 UTC (permalink / raw)
To: gcc-help
* Yang Zhang (yanghatespam@gmail.com) [20080702 06:50]:
> Steering this thread back on track: I'm still not sure why these are
> different. So far, I know that both long long and int64_t are 64-bit
> signed integral types.
int64_t is a typedef, *not* a base type. The actual type depends on the
platform. For i386, int64_t is a typedef for long long, on an LP64 arch as
x86-64, it's a typedef for long as longs are 64 bits.
> but I was hoping someone would be able to explain things to a bit more
> depth (e.g. rationale).
Does the above make it clearer?
Philipp
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-07-16 11:22 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-01 19:18 int64_t == long long Yang Zhang
2008-07-01 19:33 ` John Love-Jensen
2008-07-01 20:02 ` Yang Zhang
2008-07-01 20:19 ` Wesley Smith
2008-07-01 20:26 ` Yang Zhang
2008-07-01 23:47 ` John Love-Jensen
2008-07-02 4:50 ` Yang Zhang
2008-07-02 5:09 ` John Love-Jensen
2008-07-02 5:30 ` Yang Zhang
2008-07-16 20:37 ` Philipp Thomas
2008-07-16 0:31 ` Yang Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).