Plauger,size_t和ptrdiff_t [英] Plauger, size_t and ptrdiff_t
问题描述
在另一个帖子中,海报提到了Posix ssize_t定义
(size_t的签名版本)。我最初的反应是想知道当ptrdiff_t已被定义为
时,Posix定义的
点是什么。
我认为ptrdiff_t必须与size_t的大小相同来自
Plauger的标准C库,他声明...总是
签名类型与4无符号类型具有相同的位数
为size_t选择...对于
实现,这种语言不排除一个是
和另一个长期,只要sizeof(int)== sizeof(long)。
现在我看不到标准中需要的任何地方,至少不是直接的
,似乎是unsigned int和
prtdiff_t of long(其中int和long是不同的大小)将是
。 C99将SIZE_MAX定义为至少65535,并且
PTRDIFF_MIN / MAX至少为 - / + 65535。
所以size_t和ptrdiff_t必须是相同尺寸(或基本类型)或
不是吗?
In another thread, a poster mentioned the Posix ssize_t definition
(signed version of size_t). My initial reaction was to wonder what the
point of the Posix definition was when ptrdiff_t was already defined as
such.
I got the idea that ptrdiff_t had to be the same size as size_t from
Plauger''s "The Standard C Library," where he states "... It is always
the signed type that has the same number of bits as the4 unsigned type
chosen for size_t..." This language would not rule out one being int
and the other long so long as sizeof(int)==sizeof(long) for the
implementation.
Now I can''t see anywhere in the standard that would require that, at
least not directly, and it seems that a size_t of unsigned int and a
prtdiff_t of long (where int and long are different sizes) would be
possible. C99 defines SIZE_MAX as being at least 65535, and
PTRDIFF_MIN/MAX as being at least -/+65535.
So do size_t and ptrdiff_t have to be the same size (or base type) or
not?
推荐答案
ro *********** @ yahoo.com schrieb:
In另一个帖子,一张海报提到了Posix ssize_t定义
(size_t的签名版本)。我最初的反应是想知道当ptrdiff_t已被定义为
时,Posix定义的含义是什么。
我认为ptrdiff_t必须大小相同作为size_t来自
Plauger的标准C库,他声明......总是
签名类型,其具有与为size_t选择的4无符号类型相同的位数...对于
实现,这种语言不排除一个是int
而另一个只要sizeof(int)== sizeof(long)。
现在我可以'在标准的任何地方都可以看到,至少不是直接的,并且似乎uns_int的size_t和长的
prtdiff_t(其中int和long是不同的大小)将是
可能。 C99将SIZE_MAX定义为至少65535,并且将PTRDIFF_MIN / MAX定义为至少 - / + 65535。
大小_t和ptrdiff_t必须大小相同(或基本类型)或者
不是?
In another thread, a poster mentioned the Posix ssize_t definition
(signed version of size_t). My initial reaction was to wonder what the
point of the Posix definition was when ptrdiff_t was already defined as
such.
I got the idea that ptrdiff_t had to be the same size as size_t from
Plauger''s "The Standard C Library," where he states "... It is always
the signed type that has the same number of bits as the4 unsigned type
chosen for size_t..." This language would not rule out one being int
and the other long so long as sizeof(int)==sizeof(long) for the
implementation.
Now I can''t see anywhere in the standard that would require that, at
least not directly, and it seems that a size_t of unsigned int and a
prtdiff_t of long (where int and long are different sizes) would be
possible. C99 defines SIZE_MAX as being at least 65535, and
PTRDIFF_MIN/MAX as being at least -/+65535.
So do size_t and ptrdiff_t have to be the same size (or base type) or
not?
他们不是。对于大多数实现,所声明的连接
将保持。
size_t,ssize_t和ptrdiff_t的类型定义为各自的
_roles_以及抽象。
干杯
Michael
-
电子邮箱:我的是/在/ gmx / dot / de address。
They don''t. For most implementations, the stated connection
will hold.
size_t, ssize_t and ptrdiff_t are typedefed for their respective
_roles_ as well as for abstraction.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
" ro *********** @ yahoo.com" <为RO *********** @ yahoo.com>写道:
"ro***********@yahoo.com" <ro***********@yahoo.com> writes:
在另一个帖子中,海报提到了Posix ssize_t定义
(size_t的签名版本)。我最初的反应是想知道当ptrdiff_t已被定义为
时,Posix定义的含义是什么。
我认为ptrdiff_t必须大小相同作为size_t来自
Plauger的标准C库,他声明......总是
签名类型,其具有与为size_t选择的4无符号类型相同的位数...对于
实现,这种语言不排除一个是int
而另一个只要sizeof(int)== sizeof(long)。
现在我可以'在标准的任何地方都可以看到,至少不是直接的,并且似乎uns_int的size_t和长的
prtdiff_t(其中int和long是不同的大小)将是
可能。 C99将SIZE_MAX定义为至少65535,并且将PTRDIFF_MIN / MAX定义为至少 - / + 65535。
大小_t和ptrdiff_t必须大小相同(或基本类型)或者
不是?
In another thread, a poster mentioned the Posix ssize_t definition
(signed version of size_t). My initial reaction was to wonder what the
point of the Posix definition was when ptrdiff_t was already defined as
such.
I got the idea that ptrdiff_t had to be the same size as size_t from
Plauger''s "The Standard C Library," where he states "... It is always
the signed type that has the same number of bits as the4 unsigned type
chosen for size_t..." This language would not rule out one being int
and the other long so long as sizeof(int)==sizeof(long) for the
implementation.
Now I can''t see anywhere in the standard that would require that, at
least not directly, and it seems that a size_t of unsigned int and a
prtdiff_t of long (where int and long are different sizes) would be
possible. C99 defines SIZE_MAX as being at least 65535, and
PTRDIFF_MIN/MAX as being at least -/+65535.
So do size_t and ptrdiff_t have to be the same size (or base type) or
not?
标准中size_t和ptrdiff_t没有要求
相同的大小,但是我不知道他们在b
不同的任何实现。
ptrdiff_t是减去两个结果的有符号整数类型
指针" ;; size_t是
sizeof运算符的结果的无符号整数类型。
假设系统仅支持最大65535字节的对象。 sizeof
运算符只能产生0到65535之间的值,所以16位是足够的b / b
指针减去指向
$ b $元素的指针b 65535字节的数组可以产生-65535到+65535的值,所以
ptrdiff_t必须至少为17位。
-
Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti。 net / ~kst>
圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
There''s no requirement in the standard for size_t and ptrdiff_t to be
the same size, but I don''t know of any implementation where they
differ.
ptrdiff_t is "the signed integer type of the result of subtracting two
pointers"; size_t is "the unsigned integer type of the result of the
sizeof operator".
Suppose a system only supports objects up to 65535 bytes. The sizeof
operator can only yield values from 0 to 65535, so 16 bits are
sufficient, but pointer subtraction for pointers to elements of an
array of 65535 bytes could yield values from -65535 to +65535, so
ptrdiff_t would have to be at least 17 bits.
--
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.
" Keith Thompson" < KS *** @ mib.org>在消息中写道
news:ln ************ @ nuthaus.mib.org ...
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
" ro ***********@yahoo.com" <为RO *********** @ yahoo.com>写道:
"ro***********@yahoo.com" <ro***********@yahoo.com> writes:
在另一个帖子中,海报提到了Posix ssize_t定义
(size_t的签名版本)。我最初的反应是想知道当ptrdiff_t已被定义为
时,Posix定义的含义是什么。
我认为ptrdiff_t必须大小相同作为size_t来自
Plauger的标准C库,他声明......总是
签名类型,其具有与为size_t选择的4无符号类型相同的位数...对于
实现,这种语言不排除一个是int
而另一个只要sizeof(int)== sizeof(long)。
现在我可以'在标准的任何地方都可以看到,至少不是直接的,并且似乎uns_int的size_t和长的
prtdiff_t(其中int和long是不同的大小)将是
可能。 C99将SIZE_MAX定义为至少65535,并且将PTRDIFF_MIN / MAX定义为至少 - / + 65535。
大小_t和ptrdiff_t必须大小相同(或基本类型)或者
不是?
In another thread, a poster mentioned the Posix ssize_t definition
(signed version of size_t). My initial reaction was to wonder what the
point of the Posix definition was when ptrdiff_t was already defined as
such.
I got the idea that ptrdiff_t had to be the same size as size_t from
Plauger''s "The Standard C Library," where he states "... It is always
the signed type that has the same number of bits as the4 unsigned type
chosen for size_t..." This language would not rule out one being int
and the other long so long as sizeof(int)==sizeof(long) for the
implementation.
Now I can''t see anywhere in the standard that would require that, at
least not directly, and it seems that a size_t of unsigned int and a
prtdiff_t of long (where int and long are different sizes) would be
possible. C99 defines SIZE_MAX as being at least 65535, and
PTRDIFF_MIN/MAX as being at least -/+65535.
So do size_t and ptrdiff_t have to be the same size (or base type) or
not?
标准中没有要求size_t和ptrdiff_t的大小相同,但我不知道任何他们不同的实现。
ptrdiff_t是减去两个
指针的结果的有符号整数类型; size_t是
sizeof运算符的结果的无符号整数类型。
假设系统仅支持最大65535字节的对象。 sizeof
运算符只能产生0到65535之间的值,所以16位足够了,但是对于指向65535字节的
数组元素的指针的指针减法可以产生从-65535到-65535的值+65535,所以
ptrdiff_t必须至少为17位。
There''s no requirement in the standard for size_t and ptrdiff_t to be
the same size, but I don''t know of any implementation where they
differ.
ptrdiff_t is "the signed integer type of the result of subtracting two
pointers"; size_t is "the unsigned integer type of the result of the
sizeof operator".
Suppose a system only supports objects up to 65535 bytes. The sizeof
operator can only yield values from 0 to 65535, so 16 bits are
sufficient, but pointer subtraction for pointers to elements of an
array of 65535 bytes could yield values from -65535 to +65535, so
ptrdiff_t would have to be at least 17 bits.
是的,但是。 X3J11痛苦地意识到了这个问题,这就是为什么
我们明确决定允许一些指针差异为/ b $ b无法代表ptrdiff_t。我说了我说的是因为那时候b $ b是现实,这肯定是
委员会的意图。它是否被语言捕获得很好...
BTW,即使你得到ptrdiff_t溢出,也可以(非常常见)
两个补码有溢出的安静环绕的机器有很多很少的情况。
PJ Plauger
Dinkumware,Ltd。
http://www.dinkumware.com
这篇关于Plauger,size_t和ptrdiff_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!