长与.诠释 C/C++ - 有什么意义?

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

我最近了解到,C/C++ 中的 longint 的长度相同.简单地说,为什么?甚至在语言中包含数据类型似乎几乎毫无意义.它是否有任何 int 没有的特定用途?我知道我们可以像这样声明一个 64 位 int:

As I've learned recently, a long in C/C++ is the same length as an int. To put it simply, why? It seems almost pointless to even include the datatype in the language. Does it have any uses specific to it that an int doesn't have? I know we can declare a 64-bit int like so:

long long x = 0;

但是为什么语言选择这样做,而不是仅仅使 long 好...比 int 长?其他语言(例如 C#)可以做到这一点,那么为什么不使用 C/C++?

But why does the language choose to do it this way, rather than just making a long well...longer than an int? Other languages such as C# do this, so why not C/C++?

推荐答案

使用 C 或 C++ 编写时,每种数据类型都是特定于体系结构和编译器的.在一个系统上 int 是 32,但您可以找到它是 16 或 64 的系统;它没有定义,所以由编译器决定.

When writing in C or C++, every datatype is architecture and compiler specific. On one system int is 32, but you can find ones where it is 16 or 64; it's not defined, so it's up to compiler.

至于 longint,它来自时代,标准整数是 16 位,而 long 是 32 位整数 - 而且它确实 比 int 长.

As for long and int, it comes from times, where standard integer was 16bit, where long was 32 bit integer - and it indeed was longer than int.

相关文章