为什么C ++ int和long类型都为4个字节? [英] Why are C++ int and long types both 4 bytes?

查看:302
本文介绍了为什么C ++ int和long类型都为4个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多资源,包括 Microsoft ,同时将int和long类型都引用为4个字节,并且具有(有符号)-2,147,483,648到2,147,483,647之间的范围。如果长型原始类型实际上没有提供更大范围的值,那有什么意义呢?

Many sources, including Microsoft, reference both the int and long type as being 4 bytes and having a range of (signed) -2,147,483,648 to 2,147,483,647. What is the point of having a long primitive type if it doesn't actually provide a larger range of values?

推荐答案

关于整数类型的保证是:

The only things guaranteed about integer types are:


  1. sizeof(char)== 1

  2. sizeof(char)< = sizeof(short)

  3. sizeof(short)< = sizeof(int)

  4. sizeof(int)< = sizeof(long)

  5. sizeof(long)< = sizeof(long long)

  6. sizeof(char)* CHAR_BIT> = 8

  7. sizeof(short)* CHAR_BIT> = 16

  8. sizeof(int)* CHAR_BIT> = 16

  9. sizeof(long long)* CHAR_BIT> = 32

  10. sizeof(long long)* CHAR_BIT > = 64

  1. sizeof(char) == 1
  2. sizeof(char) <= sizeof(short)
  3. sizeof(short) <= sizeof(int)
  4. sizeof(int) <= sizeof(long)
  5. sizeof(long) <= sizeof(long long)
  6. sizeof(char) * CHAR_BIT >= 8
  7. sizeof(short) * CHAR_BIT >= 16
  8. sizeof(int) * CHAR_BIT >= 16
  9. sizeof(long) * CHAR_BIT >= 32
  10. sizeof(long long) * CHAR_BIT >= 64

其他内容是实现定义的。多亏了(4), long int 都可以具有相同的大小,但必须至少为32位(感谢(9))。

The other things are implementation defined. Thanks to (4), both long and int can have the same size, but it must be at least 32 bits (thanks to (9)).

这篇关于为什么C ++ int和long类型都为4个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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