我可以假设`长int`的大小总是4个字节? [英] Can I assume the size of `long int` is always 4 bytes?

查看:195
本文介绍了我可以假设`长int`的大小总是4个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时总是真的长整型(其中据我了解是的同义词)是 4 字节?我可以依靠吗?如果不是,可以将它用于基于POSIX的操作系统是真的吗?

Is it always true that long int (which as far as I understand is a synonym for long) is 4 bytes? can I rely on that? If not, could it be true for a POSIX based OS?

推荐答案

该标准无话可说从字符有关任何整数类型的确切大小待用。通常情况下,是32位系统的32位和64位系统的64位。

The standards say nothing regarding the exact size of any integer types aside from char. Typically, long is 32-bit on 32-bit systems and 64-bit on 64-bit systems.

所以,不,你不能对大小任何假设。如果你需要的类型的具体大小,您可以使用 stdint.h 定义的类型。它定义了以下几种类型:

So no, you can't make any assumptions on size. If you need a type of a specific size, you can use the types defined in stdint.h. It defines the following types:


  • 中int8_t :符号的8位

  • uint8_t有:8位无符号

  • int16_t :16位有符号

  • uint16_t :16位无符号

  • int32_t :32位有符号

  • uint32_t的:32位无符号

  • 的int64_t :有符号64位

  • uint64_t中:64位无符号

  • int8_t: signed 8-bit
  • uint8_t: unsigned 8-bit
  • int16_t: signed 16-bit
  • uint16_t: unsigned 16-bit
  • int32_t: signed 32-bit
  • uint32_t: unsigned 32-bit
  • int64_t: signed 64-bit
  • uint64_t: unsigned 64-bit

stdint.h 头中的标准,在部分7.18.1.1精确宽度类型。该标准规定,这些类型定义是可选的,但他们在大多数的实现存在。

The stdint.h header is described in section 7.18 of the standard, with exact width types in section 7.18.1.1. The standard states that these typedefs are optional, but they exist on most implementations.

这篇关于我可以假设`长int`的大小总是4个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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