_ _int64 64位整数

来源:互联网 发布:程序员励志桌面壁纸 编辑:程序博客网 时间:2024/05/16 15:33

【MSVC】http://msdn.microsoft.com/en-us/library/aa261215(v=vs.60).aspx

允许使用64位的整数

使用之前先判断是否支持64位整数

_#if defined (_INTEGRAL_MAX_BITS) && \  _INTEGRAL_MAX_BITS >= 64typedef signed __int64 int64;typedef unsigned __int64 uint64;#else#error __int64 type not supported#endif


【GGC】

http://bytes.com/topic/c/answers/214990-defining-int64

I use this in my code#if defined(_MSC_VER) || defined(__BORLANDC__)typedef unsigned __int64 ulong64;typedef signed __int64 long64;#elsetypedef unsigned long long ulong64;typedef signed long long long64;#endifIt works for GCC, MSVC and BorlandC which will cover the vast majority ofplatforms.


The _ _int64 keyword declares a new type, a 64-bit (8-byte) integer. As with the intshort, andlong types, the _ _int64 type has a corresponding unsigned version, so the _ _int64 keyword actually can be used to create two types.

The following code sample shows how to declare two 64-bit integers, one signed and the other unsigned:

__int64            signed_big_int;unsigned __int64   unsigned_big_int;

In the printf family of run-time library functions, the format for optional prefixes includes I64, in addition to FNhl, and L. For example, the following statement includes an example of a valid format string:

printf("%I64d", x);

When manipulating 64-bit integers, no special functions are necessary. Ordinary arithmetic operators and operations behave as expected.

Note   Both the Alpha edition and the x86 edition of Visual C++ support the _ _int64 data type. However, the support in the Alpha edition is more complete; in particular, the integrated debugger recognizes _ _int64 variables in the Alpha edition but not in the x86 edition. Also, both editions provide full support for the _ _int8_ _int16, and _ _int32 types. Use of these types is not recommended, except in situations where the program must interact with a fixed-byte layout (for example, in reading records previously stored on disk).

Use of _ _int64 should be conditional on the predefined macro _INTEGRAL_MAX_BITS. This macro describes the maximum size of integers defined using the form _ _intx. For example:

_#if defined (_INTEGRAL_MAX_BITS) && \  _INTEGRAL_MAX_BITS >= 64typedef signed __int64 int64;typedef unsigned __int64 uint64;#else#error __int64 type not supported#endif

原创粉丝点击