为什么英寸长INT"具有相同的大小和QUOT; INT"?此修改器的工作原理呢? [英] Why "long int" has same size as "int"? Are this modifier works at all?
问题描述
埃姆..我种'的虽然这修饰符例如长 / 短扩展/减少创建变量时,分配的内存量,但是......
Ehm.. I kind' of though this modifiers like long / short expands / reduces amount of memory allocated when variable are created, but...
#include <stdio.h>
#define test_int int
#define long_int long int
#define long_long_int long long int
void main()
{
printf("%i\n", sizeof (test_int)); //output 4
printf("%i\n", sizeof (long_int)); //output 4. Why? wasn't I modified it's size?
printf("%i\n", sizeof (long_long_int)); //output 8
}
对于未知的我的理由,它打印的一样大小的内部和长整型相同。
我用VC ++ 2010的前preSS版。
对不起,很难找到答案谷歌,它总是显示的长和 INT 为不同的类型。
For unknown for me reason, it prints like size of int and long int are same. I use vc++ 2010 express edition. Sorry, hard to find answer in google, it always shows long and int as separate types.
推荐答案
之所以MS选择让长
即使是在64位系统32位的是,现有的Windows API,由于历史原因,使用 INT
和长
对于类似的事情,并期望是,这个混合是第32位值(一些本可以追溯到时候的Windows是一个16位系统)。因此,为了使老code转化为新的64位架构,他们选择保留长
32位,这样,应用混合 INT
和长
在不同的地方仍然编译。
The reason that MS choose to makelong
32 bits even on a 64-bit system is that the existing Windows API, for historical reasons use a mixture of int
and long
for similar things, and the expectation is that this is s 32-bit value (some of this goes back to times when Windows was a 16-bit system). So to make the conversion of old code to the new 64-bit architecture, they choose to keep long
at 32 bits, so that applications mixing int
and long
in various places would still compile.
有什么在C ++标准,它决定了一个长
应该比 INT
更大(可以肯定的ISN在大多数32位系统'T)。所有的标准说的是,短
&LT的大小= INT
&LT; = 长
- 和短
至少是16位,如果没有记错pssed为[不一定EX $ p $至少应为16位我觉得它提到的数值范围。
There is nothing in the C++ standard that dictates that a long
should be bigger than int
(it certainly isn't on most 32-bit systems). All the standard says is that the size of short
<= int
<= long
- and that short
is at least 16 bits, if memory serves [not necessarily expressed as "should be at least 16 bits", I think it mentions the range of values].
这篇关于为什么英寸长INT&QUOT;具有相同的大小和QUOT; INT&QUOT;?此修改器的工作原理呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!