长与.诠释 C/C++ - 有什么意义? [英] Long Vs. Int C/C++ - What's The Point?

查看:36
本文介绍了长与.诠释 C/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.

这篇关于长与.诠释 C/C++ - 有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆