我知道 C
sizeof
的返回类型运算符是 size_t
是 <stdint.h>
中定义的无符号整数类型.这意味着它的最大尺寸应该是 65535
如 C99
中所述标准7.18.3 :
limit of size_t
SIZE_MAX 65535
然而在gcc-4.8.2
头文件 stdint.h
已定义其大小远大于 65535
与C99
中所述相矛盾标准如下图,
/* Limit of `size_t' type. */
# if __WORDSIZE == 64
# define SIZE_MAX (18446744073709551615UL)
# else
# define SIZE_MAX (4294967295U)
# endif
请帮助我理解为什么我的误解背后存在差异或原因。
最佳答案
标准规定 SIZE_MAX
必须至少 65535。
它没有指定上限,gcc 的实现是完全有效的。
引用您引用的引用文献(强调已添加):
Its implementation-defined value shall be equal to or greater in magnitude (absolute value) than the corresponding value given below, with the same sign.
关于c - size_t 的最大尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22514803/