Http://www.byvoid.com/blog/c-int64/
C/C ++ 64-bit integer
Computer technology
Add comments4, 177 views
In C/C ++, 64 is an undefined standard data type. In today's mainstream compilers, the support for 64-type integers is also different in different forms. Generally, 64-bit integer types are long and _ int64 (VC also supports _ int64), while printf ("% LLD ", a), printf ("% i64d", A), and cout <.
This article discusses five common C/C ++ compilers that support 64-bit integers. These five compilers are GCC (mingw32), g ++ (mingw32 ), GCC (Linux i386), g ++ (Linux i386), Microsoft Visual C ++ 6.0. Unfortunately,There is no combination of definition and output methods, and these five compilers are compatible at the same time.. To thoroughly understand the 64-bit integer types of different compilers, I wrote a program to evaluate them. The results are shown in the following table.
| Variable definition |
Output Mode |
GCC (mingw32) |
G ++ (mingw32) |
GCC (Linux i386) |
G ++ (Linux i386) |
Microsoftvisual C ++ 6.0 |
| Long long |
"% LLD" |
Error |
Error |
Correct |
Correct |
Unable to compile |
| Long long |
"% I64d" |
Correct |
Correct |
Error |
Error |
Unable to compile |
| _ Int64 |
"LLD" |
Error |
Error |
Unable to compile |
Unable to compile |
Error |
| _ Int64 |
"% I64d" |
Correct |
Correct |
Unable to compile |
Unable to compile |
Correct |
| Long long |
Cout |
Non-C ++ |
Correct |
Non-C ++ |
Correct |
Unable to compile |
| _ Int64 |
Cout |
Non-C ++ |
Correct |
Non-C ++ |
Unable to compile |
Unable to compile |
| Long long |
Printint64 () |
Correct |
Correct |
Correct |
Correct |
Unable to compile |
In the above table, correct indicates that the compilation passes and the operation is completely correct. Error indicates that the compilation passes but the running result is incorrect. Failure to compile means that the compiler cannot complete the compilation at all. Observe the table above and we can find the following points:
- Long long can be defined in gcc/g ++ without platform restrictions, but not in vc6.0.
- _ Int64 is a 64-bit long integer definition method of the Win32 platform compiler. It cannot be used in Linux.
- "% LLD" is used for the Linux i386 platform compiler, and "% i64d" is used for the Win32 platform compiler.
- Cout can only be used for C ++ compilation. In vc6.0, cout does not support 64-bit long integers.