什么是“长”数据类型用于? [英] What's the 'long' data type used for?

查看:307
本文介绍了什么是“长”数据类型用于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C ++中编程了很长时间了,我非常熟悉大部分的东西。一个我从来没有理解的东西是长的数据类型。

I've been programming in C++ for quite a while now and I am pretty familiar with most of the stuff. One thing that I've never understood though is the 'long' data type.

我googled它,但我还是不知道它是什么。我发现的页面,它是相同的大小和具有相同的范围作为一个int。

I googled it but I still don't know what it is for. I've found pages that say it is the same size and has the same range as an int. So what would be the point in using it?

我在这里发现了另一个堆栈溢出问题:

I found another stack overflow question regarding this here: difference in long vs int data types in C++

似乎两者之间的唯一区别是有时在不同的系统上的大小是不同的。这是否意味着在64位机器上使用long的应用程序不能在32位机器上工作?

And it seems that the only difference between the two is that sometimes the size is different on different systems. Does that mean that an application that uses long on a 64bit machine won't work on a 32bit machine? If so then wouldn't it be better to not use them at all?

我也注意到了叫做long int甚至long long的东西!是数据类型还是修饰符?

Also I noticed stuff called "long int" or even "long long"! Is it a data type or a modifier?

推荐答案

我的标准-fu有点生锈,但我相信它的定义如下:

It is compiler dependent. My standards-fu is a bit rusty but I believe it is defined as follows:

char <= short <= int <= long <= long long

其中:

char      >= 8 bits
short     >= 16 bits
int       >= 16 bits
long      >= 32 bits
long long >= 64 bits

这意味着它完全有效, code> char = short = int = long = long long = 64bits 并且实际上,一些DSP的编译器是这样设计的。

Which means that it is perfectly valid to have char = short = int = long = long long = 64bits and in fact compilers of some DSPs are designed that way.

这强调了阅读编译器文档的重要性。

This underscores the importance of actually reading your compiler documentation.

这篇关于什么是“长”数据类型用于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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