size_t的交易是什么? [英] What's the deal with size_t?
问题描述
你好,世界!
读了这个小组一段时间我得出的结论是
这里的人被分成几个关于size_t的分数,
包括但不限于
* size_t是适用于每个包含
数量的var的东西或者以字节为单位的大小。
* size_t只应在处理库函数时使用。
* size_t应该是签名的类型(少警告)
* size_t是不必要的(内存中对象的大小永远不会超过
可以保存为整数)。
* size_t在视觉上是令人不愉快的。
* size_t杂乱/是语言的丑化
(仅解决理论问题)问题)。
* size_t使用可能是不可移植的,因为它不再是100年后的b $ b。
Sooo ...与size_t有什么关系?它应该在哪里?/ b $ b使用/避免(例子?)
Hello, World!
Reading this group for some time I came to the conclusion that
people here are split into several fractions regarding size_t,
including, but not limited to,
* size_t is the right thing to use for every var that holds the
number of or size in bytes of things.
* size_t should only be used when dealing with library functions.
* size_t should really be a signed type (less warnings)
* size_t is unnecessary (size of object in memory never exceeds
what can be held in an integer).
* size_t is visually unpleasant.
* size_t clutters up / is an uglification of the language
(solving only a theoretical problem).
* size_t usage may be non-portable because it won''t be around
anymore in 100 years.
Sooo... what''s the real deal with size_t? Where should it be
used/avoided (examples?)
推荐答案
Tubular Technician说:
Tubular Technician said:
Sooo ...与size_t有什么关系?应该在哪里使用/避免使用
(示例?)
Sooo... what''s the real deal with size_t? Where should it be
used/avoided (examples?)
观察标准库使用size_t的位置,方式和原因。然后去你b $ b并做同样的事。标准库经常(尽管绝不是总是b / b
)是您自己的代码中良好实践的合理指南。
许多标准库函数使用size_t,不仅要指定对象的大小,还要枚举对象。
-
Richard Heathfield< http://www.cpax.org.uk>
电子邮件:-http:// www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
Observe where, how, and why the standard library uses size_t. Then go thou
and do likewise. The standard library is very often (although by no means
always) a reasonable guide to good practice in your own code.
A great many standard library functions use size_t, not only to specify the
size of an object, but also to enumerate objects.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Tubular Technician写道:
Tubular Technician wrote:
Hello,World!
读了这个小组一段时间我得出的结论是
这里的人被分成几个关于size_t的分数,
包括但不限于,
* size_t是用于保存
数量或大小以字节为单位的每个var的正确选择。
Hello, World!
Reading this group for some time I came to the conclusion that
people here are split into several fractions regarding size_t,
including, but not limited to,
* size_t is the right thing to use for every var that holds the
number of or size in bytes of things.
据我所知,所有的c-library I / O函数(以及很多
) item of items参数)都使用size_t,所以最好是
匹配类型。
as far as I''m aware, all of the c-library I/O functions (as well as many
that take "number of items" arguments) all use size_t, so it is best to
match types.
>
* size_t只应在处理库函数时使用。
>
* size_t should only be used when dealing with library functions.
这是很多库函数;-)
That''s a lot of library functions ;-)
>
* size_t应该是签名类型(少警告)
>
* size_t should really be a signed type (less warnings)
除了size_t通常用于保存可能大于
$的值b $ ba有符号整数可以保留。
有一个签名的ssize_t
except that size_t is often used to hold values that may be larger than
a signed integer can hold.
there is an ssize_t which is signed
>
* size_t是不必要的(内存中对象的大小永远不会超过
可以保存在整数中)。
>
* size_t is unnecessary (size of object in memory never exceeds
what can be held in an integer).
size_t通常用于表示磁盘上对象的大小,这可能很容易超过有符号整数中的对象。
32位体系结构上的最大size_t是4GB,我不完全确定64位体系结构上是否会更改
,但Linux文件大小可以达到在
至少4GB并且我相信Linux也支持至少4GB的内存,
所以如果你想要你的软件使用有符号整数是不够的
便携式。
size_t is often used to refer to sizes of objects on disk, which can
easily exceed what can be held in a signed integer.
Max size_t is 4GB on 32bit architectures, I''m not entirely sure if that
changes on 64bit architectures, but Linux file sizes can range up to at
least 4GB and I believe that Linux also supports at least 4GB of memory,
so using a signed integer is not sufficient if you want your software to
be portable.
>
* size_t在视觉上令人不快。
>
* size_t is visually unpleasant.
这是在旁观者的眼中,并不是技术上的原因
使用/不使用size_t >
>
* size_t杂乱/是语言的uglification
(仅解决理论问题)。
>
* size_t clutters up / is an uglification of the language
(solving only a theoretical problem).
再次,不是一个非常技术性的论点。
Again, not a very technical argument.
* size_t使用可能是不可移植的,因为它100年后不再是
了。
* size_t usage may be non-portable because it won''t be around
anymore in 100 years.
我不会在100年内出现,所以我不是非常担心它是否会赢得或者赢得''到那时为止。
我怀疑,size_t不会消失。
I won''t be around in 100 years, so I''m not terribly worried whether it
will or won''t be around by then.
I suspect, however, that size_t will not be going away.
>
Sooo ...与size_t有什么关系?应该在哪里使用/避免使用
(例子?)
>
Sooo... what''s the real deal with size_t? Where should it be
used/avoided (examples?)
每当你调用一个库函数时都应该使用它br />
使用它,并且可能,只要你想表达一个对象的大小
,以字节为单位。
Jeff
It should be used whenever you make a call to a library functions which
uses it and, likely, whenever you want to express the size of an object
in bytes.
Jeff
Tubular Technician< no@spam.invalidwrites:
Tubular Technician <no@spam.invalidwrites:
* size_t是每个var使用的正确的东西持有
的数量或大小以字节为单位。
* size_t is the right thing to use for every var that holds the
number of or size in bytes of things.
只有内存中保存的对象的大小,或者数字或大小
,不能超过最大大小对象持有
内存。因此,size_t不适合保存
磁盘文件的大小,因为磁盘文件可能比内存大(使用
off_t)。
-
Ben Pfaff
http://benpfaff.org
这篇关于size_t的交易是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!