size_t或ssize_t [英] size_t or ssize_t
问题描述
我使用的是size_t和ssize_t。但我对它们很困惑。
< ssize_t>
typedef int __ssize_t;
typedef __ssize_t ssize_t;
< size_t>
typedef unsigned int size_t;
即:
ssize_t = int
size_t = unsigned int
我看到它们的范围是:
int(ssize_t): - 32767 ~32767
unsigned int(size_t):0~65535
我的问题是:是否有必要使用ssize_t? (大小可以减去
?)
谢谢。
"滚装***** @ gmail.com" <滚装***** @ gmail.com>写道:我使用的是size_t和ssize_t。但我对它们感到困惑。
< ssize_t>
typedef int __ssize_t;
typedef __ssize_t ssize_t;
< size_t>
typedef unsigned int size_t;
那是:
ssize_t = int
size_t = unsigned int
我看到它们的范围是:
int(ssize_t): - 326767~32767
unsigned int(size_t):0~65535
我的问题是:是否有必要使用ssize_t? (大小可以减去
?)
size_t在< stddef.h>中定义;它是一个无符号类型,
的结果是sizeof运算符。它不一定是unsigned int(例如,它可以是
无符号长),并且它通常比0..65535的范围更大
。
ssize_t未在标准C中定义。它是POSIX扩展,因此如果你关心绝对可移植性,你不应该使用它.b $ b不应该使用它。
< OFF_TOPIC>
ssize_t,如果已定义,则是size_t的等效签名。
据推测只有在你需要存储负值
值时才应该使用。 Open Group Base规范称它用于计数
字节或错误指示。
< / OFF_TOPIC>
-
Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>
圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
Ro ***** @ gmail。 com 写道:
我使用的是size_t和ssize_t。但我对他们很困惑。
即:
ssize_t = int
size_t = unsigned int
在你的特定机器上。
其他机器可能会有所不同。
我看到它们的范围是:
int(ssize_t): - 32767~32767
unsigned int(size_t):0~65535
我的问题是:是否有必要使用ssize_t? (大小可以减去
?)
在什么情况下需要?
size_t来自标准C,是无符号类型用于对象大小。
ssize_t来自posix,是一个用于计数字节的签名类型或
一个错误指示。
Nils O. Sel?sdal写道:Ro ***** @ gmail.com 写道:
我使用的是size_t和ssize_t。但我对它们很困惑。那就是:
ssize_t = int
size_t = unsigned int
在你的特定机器上。在
其他机器上可能会有所不同。
是的,我明白了。我正在使用带有Fedora Core 4的PC。
谢谢我看到它们的范围是:
int(ssize_t): - 32767~32767
unsigned int(size_t):0~65535
我的问题是:是否有必要使用ssize_t? (大小可以减去
?)
在什么情况下需要?
size_t来自标准C,是一种用于对象大小的无符号类型。 />
ssize_t来自posix,是用于计数字节的签名类型或
错误指示。
Hi,
I am using size_t and ssize_t . But I am confused about them.
<ssize_t>
typedef int __ssize_t;
typedef __ssize_t ssize_t;
<size_t >
typedef unsigned int size_t;
That is:
ssize_t = int
size_t = unsigned int
I see the range of them are :
int ( ssize_t ) : -32767~32767
unsigned int ( size_t ) : 0~65535
My question is : Is that necessary to use ssize_t ? ( size can be minus
? )
Thanks.
"Ro*****@gmail.com" <Ro*****@gmail.com> writes:I am using size_t and ssize_t . But I am confused about them.
<ssize_t>
typedef int __ssize_t;
typedef __ssize_t ssize_t;
<size_t >
typedef unsigned int size_t;
That is:
ssize_t = int
size_t = unsigned int
I see the range of them are :
int ( ssize_t ) : -32767~32767
unsigned int ( size_t ) : 0~65535
My question is : Is that necessary to use ssize_t ? ( size can be minus
? )
size_t is defined in <stddef.h>; it''s an unsigned type, the result of
the sizeof operator. It won''t necessarily be unsigned int (it could
be unsigned long, for example), and it will often have a range greater
than 0..65535.
ssize_t is not defined in standard C. It''s a POSIX extension, so you
shouldn''t use it if you care about absolute portability.
<OFF_TOPIC>
ssize_t, if it''s defined, is the signed equivalent of size_t.
Presumably it should be used only if you need to store negative
values. The Open Group Base Specification says it''s "Used for a count
of bytes or an error indication."
</OFF_TOPIC>
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Ro*****@gmail.com wrote:Hi,
I am using size_t and ssize_t . But I am confused about them. That is:
ssize_t = int
size_t = unsigned int On your particular machine. Could be something different on
other machines.
I see the range of them are :
int ( ssize_t ) : -32767~32767
unsigned int ( size_t ) : 0~65535
My question is : Is that necessary to use ssize_t ? ( size can be minus
? )
necessary in what context ?
size_t comes from standard C,is an unsigned type used for sizes of objects.
ssize_t comes from posix, is a signed type used for a count of bytes or
an error indication.
Nils O. Sel?sdal wrote:Ro*****@gmail.com wrote:Hi,
I am using size_t and ssize_t . But I am confused about them.That is:
ssize_t = int
size_t = unsigned int
On your particular machine. Could be something different on
other machines.
Yes, I see. I''m using a PC with Fedora Core 4.
ThanksI see the range of them are :
int ( ssize_t ) : -32767~32767
unsigned int ( size_t ) : 0~65535
My question is : Is that necessary to use ssize_t ? ( size can be minus
? )
necessary in what context ?
size_t comes from standard C,is an unsigned type used for sizes of objects.
ssize_t comes from posix, is a signed type used for a count of bytes or
an error indication.
这篇关于size_t或ssize_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!