8 位、16 位、32 位处理器/微 Controller 中整数的大小是多少?
我想这取决于内部累加器/寄存器的大小。但不确定。
谢谢
最佳答案
我只知道一种定义 integer
数据类型的编程语言,但它很少用于 8 位和 16 位架构。 C 是用于 8 位、16 位和 32 位体系结构编程的最广泛使用的语言,因此我假设您正在寻找 C 上下文中的答案。
C 中有几种“整数”数据类型: char
、 short
、 int
、 long
等...,但我会假设你真正的意思是 int
数据类型。int
的大小不是由体系结构定义的,而是由 C 编程语言规范定义的,并且非常模糊。
A ‘‘plain’’
int
object has the natural size suggested by the architecture of the execution environment (large enough to contain any value in the rangeINT_MIN
toINT_MAX
as defined in the header<limits.h>
).
我解释这意味着它是由编译器的实现决定的。
您可以在此处找到 C11 标准的最新公开可用版本(在撰写此答案时): http://www.open-std.org/jtc1/sc22/wg14/www/standards.html 。
以下是我为帮助回答这个问题而进行的一些测试:
sizeof(int)
在使用 GCC 4.3.2 (WinAVR 20081205) 编译时返回 2(例如 16 位) sizeof(int)
在使用 GCC 4.9.2 编译时返回 4(例如 32 位)。 sizeof(int)
都会返回 4(例如 32 位)。使用 Visual Studio 2013 和 GCC 4.9.2 进行测试。 一个更有趣的答案是为什么选择这些值。
关于integer - 8 位、16 位、32 位处理器/微 Controller 中整数的大小是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29618439/