int64_t 的定义

2022-01-14 00:00:00 c integer long-integer c++

我是 C/C++ 新手,所以我有几个关于基本类型的问题:

I am new to C/C++, so I have a couple of questions about a basic type:

a) 你能解释一下 int64_tlong (long int) 的区别吗?据我了解,两者都是 64 位整数.有什么理由选择其中一个吗?

a) Can you explain to me the difference between int64_t and long (long int)? In my understanding, both are 64 bit integers. Is there any reason to choose one over the other?

b) 我试图在网上查找 int64_t 的定义,但没有成功.有没有我需要咨询这些问题的权威来源?

b) I tried to look up the definition of int64_t on the web, without much success. Is there an authoritative source I need to consult for such questions?

c) 对于使用 int64_t 编译的代码,我目前包括 ,这对我来说没有多大意义.是否有其他包含提供 int64_t 的声明?

c) For code using int64_t to compile, I am currently including <iostream>, which doesn't make much sense to me. Are there other includes that provide a declaration of int64_t?

推荐答案

a) 你能解释一下 int64_tlong (long int) 的区别吗?据我了解,两者都是 64 位整数.有什么理由选择其中一个吗?

a) Can you explain to me the difference between int64_t and long (long int)? In my understanding, both are 64 bit integers. Is there any reason to choose one over the other?

前者是有??符号整数类型,正好 64 位.后者是至少 32 位的有符号整数类型.

The former is a signed integer type with exactly 64 bits. The latter is a signed integer type with at least 32 bits.

b) 我试图在网上查找 int64_t 的定义,但没有成功.有没有我需要咨询这些问题的权威来源?

b) I tried to look up the definition of int64_t on the web, without much success. Is there an authoritative source I need to consult for such questions?

http://cppreference.com 在这里介绍:http://en.cppreference.com/w/cpp/types/integer.然而,权威来源是 C++ 标准(这个特定的位可以在 §18.4 整数类型 [cstdint] 中找到).

http://cppreference.com covers this here: http://en.cppreference.com/w/cpp/types/integer. The authoritative source, however, is the C++ standard (this particular bit can be found in §18.4 Integer types [cstdint]).

c) 对于使用 int64_t 编译的代码,我包括 ,这对我来说没有多大意义.是否有其他包含提供 int64_t 的声明?

c) For code using int64_t to compile, I am including <iostream>, which doesn't make much sense to me. Are there other includes that provide a declaration of int64_t?

(在命名空间 std 下)或 中声明.stdint.h><inttypes.h>(在全局命名空间中).

It is declared in <cstdint> or <cinttypes> (under namespace std), or in <stdint.h> or <inttypes.h> (in the global namespace).

相关文章