Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在GNU/Linux中表示64位整数_C++_C_64 Bit_Long Integer - Fatal编程技术网

C++ 在GNU/Linux中表示64位整数

C++ 在GNU/Linux中表示64位整数,c++,c,64-bit,long-integer,C++,C,64 Bit,Long Integer,我使用Ubuntu 10.10(64位),代码为 Gcc,我想在C++程序中使用64位整数。p> 在我的系统上,sizeof(long)、sizeof(long-long-int)和sizeof(int64\t)的输出都是8字节(64位) 对于使用64位整数,您建议使用哪种限定符(long、long或int64_t) int64\t——这是因为它是最可移植的表示形式。其他两个可以在其他机器上以不同的方式表示 int64\t.如果需要64位,请显式声明它。long和long的大小因机器而异。您需要

我使用Ubuntu 10.10(64位),代码为<> Gcc,我想在C++程序中使用64位整数。p> 在我的系统上,
sizeof(long)
sizeof(long-long-int)
sizeof(int64\t)
的输出都是8字节(64位)


对于使用64位整数,您建议使用哪种限定符(
long
long
int64_t

int64\t
——这是因为它是最可移植的表示形式。其他两个可以在其他机器上以不同的方式表示

int64\t.如果需要64位,请显式声明它。long和long的大小因机器而异。

您需要64位还是至少64位

使用
int64\u t
int-least64\u t
int-fast64\u t
中最清楚表达您意图的一种。(在当前系统上,几乎可以肯定这三种类型都是相同的,但记录您的意图很有价值。)

所有实现必须提供
int\u least64\u t
int\u fast64\u t
。至少在理论上,
int64\t
可能不存在(例如,如果编译器有128位类型但没有64位类型,或者如果有符号整数不使用2的补码表示)


(但在我见过的每个C99 ish实现中,
long
正好是64位,并且
int64\t
存在。)

为64位整数定义自定义类型,并在代码中使用它。使用指令#ifdef,编译器可以选择正确的指令。统一某些整数的示例如下:

#ifdef (_MSC_VER)

#include <basetsd.h>

#define int8_t  INT8
#define uint8_t UINT8
#define int16_t  INT16
#define uint16_t UINT16
#define int32_t INT32
#define uint32_t UINT32
#define int64_t INT64
#define uint64_t UINT64

#else

#include <inttypes.h>

#endif

typedef uint8_t u8_t;
typedef  int8_t s8_t;
typedef uint16_t u16_t;
typedef  int16_t s16_t;
typedef uint32_t u32_t;
typedef  int32_t s32_t;
typedef uint64_t u64_t;
typedef  int64_t s64_t;
#ifdef(_MSC_VER)
#包括
#定义int8\u t int8
#定义uint8\u t uint8
#定义int16\u t int16
#定义uint16\u t uint16
#定义int32\u t int32
#定义uint32\u t uint32
#定义int64\u t int64
#定义uint64\u t uint64
#否则
#包括
#恩迪夫
类型定义uint8\u t u8\u t;
typedef int8_t s8_t;
类型定义uint16_t u16_t;
typedef int16_t s16_t;
类型定义uint32\u t u32\u t;
typedef int32_t s32_t;
类型定义uint64\u t u64\u t;
typedef int64_t s64_t;

+1。考虑Win 64 LLP64和UNIX LP64:不要把它放进你的头上。您将给您的用户带来如此多的痛苦此标题可能会导致以下问题: