C中的int总是32位吗? [英] Is int in C Always 32-bit?

查看:25
本文介绍了C中的int总是32位吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与以下问题有关,

如何在 C 中声明 32 位整数

有几个人提到 int 在大多数平台上始终是 32 位的.我很好奇这是不是真的.

Several people mentioned int is always 32-bit on most platforms. I am curious if this is true.

您知道任何具有不同大小的 int 的现代平台吗?忽略具有 8 位或 16 位架构的恐龙平台.

Do you know any modern platforms with int of a different size? Ignore dinosaur platforms with 8-bit or 16-bit architectures.

注意: 我已经知道如何从另一个问题中声明一个 32 位整数.这更像是一项调查,找出哪些平台(CPU/OS/Compiler)支持其他大小的整数.

推荐答案

正如一些人所说,如果您想使用特定大小的变量,则不能保证 'int' 是 32 位,尤其是在编写涉及位操作的代码,您应该使用 c99 规范规定的标准整数类型".

As several people have stated, there are no guarantees that an 'int' will be 32 bits, if you want to use variables of a specific size, particularly when writing code that involves bit manipulations, you should use the 'Standard Integer Types' mandated by the c99 specification.

int8_t
uint8_t
int32_t
uint32_t

等等……

它们通常采用 [u]intN_t 的形式,其中 'u' 表示您想要一个无符号数,N 是位数

they are generally of the form [u]intN_t, where the 'u' specifies that you want an unsigned quantity, and N is the number of bits

无论您为哪个平台编译,stdint.h 中都应该有这些正确的 typedef,使用这些可以让您编写漂亮、可移植的代码 :-)

the correct typedefs for these should be available in stdint.h on whichever platform you are compiling for, using these allows you to write nice, portable code :-)

这篇关于C中的int总是32位吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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