为int用C总是32位? [英] Is int in C Always 32-bit?
问题描述
这是涉及到以下问题,
<一个href=\"http://stackoverflow.com/questions/1229131/how-to-declare-a-32-bit-integer-in-c\">http://stackoverflow.com/questions/1229131/how-to-declare-a-32-bit-integer-in-c
有几个人提到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 /编译器),支持整数。的
推荐答案
由于几个人都表示,没有保证,一个'诠释'将是32位的,如果你想使用一个特定大小的变量,尤其是当写作code,涉及的位操作,您应该使用'标准的整数类型由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
等等......
etc...
他们一般形式[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
对于这些正确的类型定义应该是在任何平台上要编译支持,利用这些可以让你写得真好,便携code stdint.h可供选择: - )
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 :-)
这篇关于为int用C总是32位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!