size_t范围 [英] size_t range
问题描述
是否有标准方法来确定最大值。 size_t的值为
编译时常量?将:
#define SIZE_T_MAX((size_t)-1)
适用于所有情况,或仅适用于2s comp。机器?
DrX
Is there a standard way to determine the max. value of size_t as a
compile-time constant? Will:
#define SIZE_T_MAX ((size_t) -1)
work in all cases, or just on 2s comp. machines?
DrX
推荐答案
Xenos写道:
有没有标准的方法来确定最大size_t的值作为编译时常量?将:
#define SIZE_T_MAX((size_t)-1)
适用于所有情况,或仅适用于2s comp。机器?
Is there a standard way to determine the max. value of size_t as a
compile-time constant? Will:
#define SIZE_T_MAX ((size_t) -1)
work in all cases, or just on 2s comp. machines?
它适用于所有情况。 Casts处理值而不是表示。
对于它的价值,C99定义了一个SIZE_MAX宏,其值是size_t的最大值
。
Jeremy。
It will work in all cases. Casts work on values, not representations.
For what it''s worth, C99 defines a SIZE_MAX macro whose value is the
maximum value of size_t.
Jeremy.
" Xenos" <做********** @ spamhate.com>在消息中写道
新闻:c5 ********* @ cui1.lmms.lmco.com ...
"Xenos" <do**********@spamhate.com> wrote in message
news:c5*********@cui1.lmms.lmco.com...
是否有标准的方法来确定最大。 size_t的值作为编译时常量?将:
#define SIZE_T_MAX((size_t)-1)
适用于所有情况,或仅适用于2s comp。机器?
Is there a standard way to determine the max. value of size_t as a
compile-time constant? Will:
#define SIZE_T_MAX ((size_t) -1)
work in all cases, or just on 2s comp. machines?
这就是我理解它的方式。 -1,转换为无符号类型,给出
该类型的最大值,无论其代表性如何。
Peter
That''s how I understand it. -1, converted to an unsigned type, gives
the maximum value for that type regardless of representation.
Peter
2004年4月9日星期五11:17:50 -0400,Xenos < do ********** @ spamhate.com>
写道:
On Fri, 9 Apr 2004 11:17:50 -0400, "Xenos" <do**********@spamhate.com>
wrote:
是否有标准方法来确定最大值。 size_t的值作为编译时常量?将:
#define SIZE_T_MAX((size_t)-1)
适用于所有情况,或仅适用于2s comp。机器?
DrX
Is there a standard way to determine the max. value of size_t as a
compile-time constant? Will:
#define SIZE_T_MAX ((size_t) -1)
work in all cases, or just on 2s comp. machines?
DrX
size_t是某些无符号整数类型的typdef。虽然((size_t)-1)
将产生可以存储在该类型中的最大值,但是
不保证返回size_t的任何函数或运算符都将
产生的价值很大。只要满足标准中的
定义,系统就可以自由地将size_t的值限制为较小的值。
所以回答问题是你的意思是最大值是否适合
size_t变量或每个定义的任何对象的最大尺寸?
< ;<删除电子邮件的del>>
size_t is a typdef for some unsigned integer type. While ((size_t)-1)
will produce the max value that can be stored in that type, there is
no guarantee that any function or operator returning a size_t will
ever produce a value that large. The system is free to limit the
value of a size_t to a lesser value as long as it satisfies the
definition in the standard.
So the return question is do you mean the max value that will fit in a
size_t variable or the largest size of any object per the definition?
<<Remove the del for email>>
这篇关于size_t范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!