size_t是否足够大以表示任何类型的大小? [英] Is size_t large enough to represent size of any type?

查看:78
本文介绍了size_t是否足够大以表示任何类型的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

size_t 是否保证足以代表任何类型的大小?根据参考:

Is size_t guaranteed to be large enough to represent size of any type? According to this reference:

size_t 可以存储理论上可能的对象的最大大小任何类型的(包括数组).

size_t can store the maximum size of a theoretically possible object of any type (including array).

通常这是一个可靠的参考,但是我在标准的相关部分中找不到任何证明或争议的证据.

This is generally a reliable reference but I could not find anything proving or disputing this claim in the relevant parts of the standard.

推荐答案

是.根据 C99,在stddef.h中定义了size_t标准(位于sizeof运算符(6.5.3.4)的部分)中:

Yes. size_t is defined in stddef.h, according to the C99 standard in the section on the sizeof operator (6.5.3.4):

结果的值是实现定义的,其类型(无符号整数类型)是 size_t ,在< stddef.h> (和其他标头)中定义.

The value of the result is implementation-defined, and its type (an unsigned integer type) is size_t, defined in <stddef.h> (and other headers).

因为

sizeof 运算符产生其操作数的大小(以字节为单位)

The sizeof operator yields the size (in bytes) of its operand

,其返回类型为 size_t size_t 必须能够包含任何类型的大小.

and its return type is size_t, size_t must be able to contain the size of any type.

这篇关于size_t是否足够大以表示任何类型的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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