为size_t的最大大小 [英] Maximum size of size_t

查看:1126
本文介绍了为size_t的最大大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 C 的sizeof 操作符返回类型为size_t 中所定义是无符号整型; stdint.h> 。这意味着它的最大尺寸应 65535 C99陈述标准的 7.18.3

I know in C return type of sizeof operator is size_t being unsigned integer type defined in <stdint.h>. Which means max size of it should be 65535 as stated in C99 standard 7.18.3:

limit of size_t
  SIZE_MAX             65535

然而,在 GCC-4.8.2 头文件 stdint.h 定义比<$其规模大得多C $ C> 65535 矛盾给在 C99 标准如下图所示,

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

/* Limit of `size_t' type.  */
# if __WORDSIZE == 64
#  define SIZE_MAX              (18446744073709551615UL)
# else
#  define SIZE_MAX              (4294967295U)
# endif

请帮助我理解为什么有我的背后misinter pretation的差异或理由。

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

推荐答案

该标准说 SIZE_MAX 必须的至少的65535。

The standard says that SIZE_MAX must be at least 65535.

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

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

引用您引用的参考(强调):

Quoting the reference you cited (emphasis added):

其实现定义的值应等于或大于比下面给出的同号的对应值幅度(绝对值)。

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

这篇关于为size_t的最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆