c++ - 为什么 C++ int 和 long 类型都是 4 个字节?

标签 c++ cpu-architecture

许多来源,包括 Microsoft ,将 int 和 long 类型都引用为 4 个字节,范围为(有符号)-2,147,483,648 到 2,147,483,647。如果长原始类型实际上不提供更大范围的值,那么它的意义何在?

最佳答案

关于整数类型的唯一保证是:

  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),两个 longint可以具有相同的大小,但必须至少为 32 位(感谢 (9))。

关于c++ - 为什么 C++ int 和 long 类型都是 4 个字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13398630/

相关文章:

c++ - 使用带命名管道的 FFMPEG 记录 RTP VP8 数据包

c++ - XCode 在为 iOS 构建时认为 C++ 文件是 C?

intel - 我不明白 cachegrind 与 perf 工具之间的缓存未命中数

assembly - 没有保护模式的 CPU 中的保护

c++ - 如何从一条线上反弹一个点?

c++ - 重载 new 和 delete C++ 以跟踪内存分配

C++ getline 错误

memory - 计算写入挂起队列的分配数量 - NV 内存出现意外的低结果

multithreading - 内存防护是否会阻塞多核CPU中的线程?

performance - 存储转发地址与数据 : What the difference between STD and STA in the Intel Optimization guide?