问题描述
我在数据类型在C程序近日来到int32_t
。我知道,它存储了32位,但不要 INT
和 INT32
做?
I came across the data type int32_t
in a C program recently. I know that it stores 32 bits, but don't int
and int32
do the same?
另外,我想在程序中使用字符
。我可以用中int8_t
呢?有什么区别?
Also, I want to use char
in a program. Can I use int8_t
instead? What is the difference?
要总结:是用C INT32,INT,int32_t和INT8和中int8_t之间的差异
推荐答案
INT32
和 int32_t
,(和之间同样 INT8
和中int8_t
)的区别是pretty简单:C标准定义中int8_t
和 int32_t
,但并没有定义命名为任何 INT8
或 INT32
- 后者(如果存在的话)可能是从其它的头或库(最有可能的predates加入的中int8_t
和 int32_t
在C99)。
Between int32
and int32_t
, (and likewise between int8
and int8_t
) the difference is pretty simple: the C standard defines int8_t
and int32_t
, but does not define anything named int8
or int32
-- the latter (if they exist at all) is probably from some other header or library (most likely predates the addition of int8_t
and int32_t
in C99).
平原 INT
是从别人有点不同。其中,中int8_t
和 int32_t
各有一个指定的大小, INT
可以是任何大小> = 16位。在不同的时间,这两个16位和32位已经相当普遍(并为一个64位实现,它应该可能是64位)。
Plain int
is quite a bit different from the others. Where int8_t
and int32_t
each have a specified size, int
can be any size >= 16 bits. At different times, both 16 bits and 32 bits have been reasonably common (and for a 64-bit implementation, it should probably be 64 bits).
在另一方面, INT
保证是present在C,每一个实现,其中中int8_t
和 int32_t
都没有。这可能是值得商榷的,这是否尽管对你很重要。如果您在小型嵌入式系统和/或旧的编译器使用C,它可能是一个问题。如果您对桌面/服务器的机器上编译现代主要使用它,它可能不会。
On the other hand, int
is guaranteed to be present in every implementation of C, where int8_t
and int32_t
are not. It's probably open to question whether this matters to you though. If you use C on small embedded systems and/or older compilers, it may be a problem. If you use it primarily with a modern compiler on desktop/server machines, it probably won't be.
很抱歉 - 错过了约字符
部分。如果(且仅当)你想保证在大小正好是8位的整数类型,你会使用中int8_t
而不是字符。如果你想存储的字符,你可能想使用字符
来代替。其尺寸可以变化(在位数方面),但它保证是正好一个字节。一个轻微的怪胎,但:有没有关于是否一个普通的字符
带符号(和许多编译器可以使任何一个,取决于编译时的标志)的保证。如果你需要确保其被签名或未签名,则需要明确指定。
Oops -- missed the part about char
. You'd use int8_t
instead of char if (and only if) you want an integer type guaranteed to be exactly 8 bits in size. If you want to store characters, you probably want to use char
instead. Its size can vary (in terms of number of bits) but it's guaranteed to be exactly one byte. One slight oddity though: there's no guarantee about whether a plain char
is signed or unsigned (and many compilers can make it either one, depending on a compile-time flag). If you need to ensure its being either signed or unsigned, you need to specify that explicitly.
这篇关于INT32,INT,int32_t和INT8和中int8_t的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!