size_t的起源?好奇。 [英] Origin of size_t? Curious.

查看:64
本文介绍了size_t的起源?好奇。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇size_t的起源是什么。我看到它通常是

typedef'将成为特定机器的原生整数。我也看到

例程如strncpy(char * t,const char * s,size_t n)。


所以,size_t是原生大小的机器或用于描述某物的实际大小(如字符串副本的len)。


如果它被命名是因为它指定的大小什么,那么我可以
还有超过65535字节的东西。如果是这样的话为什么叫

size_t。


我明白它只是一个int,但我不明白这个名字。我可以

的大小比int大。也许我可以长期存储

的大小?哇?!?!?!


这个名字的起源到底是什么?


Elvis

I am curious what the origins of size_t are. I see that it is usually
typedef''d to be the native integer size of a particular machine. I also see
that routines like strncpy(char *t, const char *s, size_t n).

So, is size_t the native size of the machine or used to describe the actual
size of something (like the len of a string copy).

If it is named because it designates the size of something, then could I
still have more than 65535 bytes of something. If so why is that called
size_t.

I understand that it is just an int, but I don''t understand the name. I can
have a size that is larger than an int. Perhaps I could store the size of
something in long? Wow?!?!?!

What the heck are the origins for the name?

Elvis

推荐答案

困惑的用户肯定:


|我很好奇size_t的起源是什么。我看到它是

|通常typedef'将是特定的原始整数大小

|机。我也看到像strncpy(char * t,const char

| * s,size_t n)这样的例程。

|

|那么,size_t是机器的原生大小还是用于描述

|某事物的实际大小(如字符串副本的len)。

|

|如果它被命名是因为它指定了某些东西的大小,那么

|我还能拥有超过65535字节的东西吗?如果是这样的话为什么是

|叫做size_t。

|

|我知道它只是一个int,但我不明白

|名称。我的大小可以大于int。也许我可以

|存储长度的东西?哇?!?!?!

|

|这个名字的起源到底是什么?


一个size_t足以代表最大数量的

< something>可能的实施。它不一定是一个int,实际上,它可能更有意义,因为它是一个长整数。

无符号长似乎更好;但是会阻止返回

(size_t)-1的错误值。


为什么size_t呢?因此,我们可以通过仅修改size_t定义

来重新编译新系统(具有不同大小size_t值)的库和应用程序




-

Morris Dovey

DeSoto Solar

德索托,爱荷华州美国
http://www.iedu.com/DeSoto
Confused User affirmed:

| I am curious what the origins of size_t are. I see that it is
| usually typedef''d to be the native integer size of a particular
| machine. I also see that routines like strncpy(char *t, const char
| *s, size_t n).
|
| So, is size_t the native size of the machine or used to describe
| the actual size of something (like the len of a string copy).
|
| If it is named because it designates the size of something, then
| could I still have more than 65535 bytes of something. If so why is
| that called size_t.
|
| I understand that it is just an int, but I don''t understand the
| name. I can have a size that is larger than an int. Perhaps I could
| store the size of something in long? Wow?!?!?!
|
| What the heck are the origins for the name?

A size_t is large enough to represent the largest number of
<something> possible to the implementation. It need not be an int and,
in fact, it''d probably make more sense for it to be a long int. An
unsigned long would seem even better; but would prevent returning
(size_t) -1 for an error value.

Why size_t at all? So that we can recompile libraries and applications
for new systems (with different size size_t values) by modifying only
the size_t definition.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto


On 2005-06-22 21:29:29 -0400,Morris Dovey <先生***** @ iedu.com>说:
On 2005-06-22 21:29:29 -0400, "Morris Dovey" <mr*****@iedu.com> said:
size_t足够大,可以代表最大数量的
< something>可能的实施。它不一定是一个int,事实上,它可能更有意义,因为它是一个长整数。
unsigned long似乎更好;但是会阻止返回
(size_t)-1表示错误值。
A size_t is large enough to represent the largest number of
<something> possible to the implementation. It need not be an int and,
in fact, it''d probably make more sense for it to be a long int. An
unsigned long would seem even better; but would prevent returning
(size_t) -1 for an error value.




你错了,size_t永远不会被签名,所以它不可能是int

或long int。

-

Clark S. Cox,III
cl ******* @ gmail.com



You are mistaken, size_t is never signed, so it cannot possibly be int
or long int.
--
Clark S. Cox, III
cl*******@gmail.com


>我很好奇size_t的起源是什么。我看到它通常是
>I am curious what the origins of size_t are. I see that it is usually
typedef'将是特定机器的原生整数大小。我也看到
例程如strncpy(char * t,const char * s,size_t n)。

所以,size_t是机器的原始大小还是用于描述实际的<某事物的大小(如字符串副本的len)。

如果它被命名是因为它指定了某些东西的大小,那么我是否仍然可以拥有超过65535字节的一些东西。


真的吗?怎么样? malloc()将size_t作为参数,因此你不能使用
malloc()更大的东西。如果你不能拿sizeof(struct foo),

它就没有必要允许你声明struct foo

超过限制一个size_t。这同样适用于大型数组。

我明白它只是一个int,但我不明白这个名字。我可以


这不是一个int。也许是无符号的int。无符号长整数更有可能。

的大小大于int。也许我可以长期存储
的大小?哇?!?!?!
typedef''d to be the native integer size of a particular machine. I also see
that routines like strncpy(char *t, const char *s, size_t n).

So, is size_t the native size of the machine or used to describe the actual
size of something (like the len of a string copy).

If it is named because it designates the size of something, then could I
still have more than 65535 bytes of something.
Really? How? malloc() takes a size_t as an argument, so you can''t
malloc() anything bigger. And if you can''t take sizeof(struct foo),
it isn''t necessary for it to allow your declaration of struct foo
that exceeds the limits of a size_t. The same applies to large arrays.
I understand that it is just an int, but I don''t understand the name. I can
It''s not an int. Unsigned int, maybe. Unsigned long is more likely.
have a size that is larger than an int. Perhaps I could store the size of
something in long? Wow?!?!?!




Gordon L. Burditt



Gordon L. Burditt


这篇关于size_t的起源?好奇。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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