C语言 size_t 的最大大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22514803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:54:50  来源:igfitidea点击:

Maximum size of size_t

cgccsizeofc99size-t

提问by Sunil Bojanapally

I know in Creturn type of sizeofoperator is size_tbeing unsigned integer type defined in <stdint.h>. Which means max size of it should be 65535as stated in C99standard 7.18.3:

我知道操作符的C返回类型sizeofsize_t<stdint.h>. 这意味着它的最大大小应该65535C99标准7.18.3 中所述

limit of size_t
  SIZE_MAX             65535

However in gcc-4.8.2header file stdint.hhas defined its size much greater than 65535contradicting to which is stated in C99standard as below shown,

然而,在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

Kindly help me in understanding why there is a difference or reason behind my misinterpretation.

请帮助我理解为什么我的误解背后存在差异或原因。

回答by Keith Thompson

The standard says that SIZE_MAXmust be at least65535.

标准说SIZE_MAX必须至少为65535。

It specifies no upper bound, and gcc's implementation is perfectly valid.

它没有指定上限,gcc 的实现是完全有效的。

Quoting the reference you cited (emphasis added):

引用你引用的参考文献(强调):

Its implementation-defined value shall be equal to or greaterin magnitude (absolute value) than the corresponding value given below, with the same sign.

其实现定义的值应等于或大于下面给出的相应值的幅度(绝对值),并具有相同的符号。