什么是size_t [英] what is size_t

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

问题描述

我偶尔会遇到使用

size_t的声明。但我不知道size_t的含义到底是什么。

我知道它是它用来隐藏平台的细节。我试过

在头文件中找到它的含义,但没有得到一个很好的答案。所以

有人可以请告诉我size_t是什么意思和什么

是它可能的值?


谢谢

I sometimes comes across statements which invloves the use of
size_t.But I dont know exactly that what is the meaning of size_t.What
I know about it is that it is used to hide the platform details.I tried
to find its meaning in the header files but did''nt got a good answer.So
can somebody please tell me that what is the meaning of size_t and what
are its possible values?

Thanks

推荐答案

ca ******** @ yahoo.com 写道:
我有时会遇到使用
size_t的语句。但是我不确切知道size_t的含义是什么。我知道它是什么它用来隐藏平台的细节。我试着在头文件中找到它的含义,但没有得到一个好的答案。所以有人请告诉我,这是什么意思size_t和
它可能的值是什么?
I sometimes comes across statements which invloves the use of
size_t.But I dont know exactly that what is the meaning of size_t.What
I know about it is that it is used to hide the platform details.I tried
to find its meaning in the header files but did''nt got a good answer.So
can somebody please tell me that what is the meaning of size_t and what
are its possible values?




`size_t''是一种适合表示内存数量的数据类型b / b对象需要,以'char''为单位表示。

这是一个整数类型(C不能跟踪
`char''的分数),它是无符号的(负数大小没有意义)。

它是`sizeof''运算符的结果类型。你传给malloc()和朋友的类型是多少

你想要的内存。

strlen()返回的类型是说

有多少重要的字符串是字符串。


每个实现选择一个真实字符串。类似`unsigned

int''或`unsigned long''(或许还有别的东西)是它的

`size_t'',取决于什么是最有意义的。你不需要
通常需要担心

封面下的'size_t'看起来像什么;"所有你关心的是它是正确的类型为

表示对象大小。


实现发布在几个标准标题中自己选择`size_t''

:< stdio.h>,< stdlib.h>,

和其他一些标题。如果你检查这些标题中的一个(大多数是实现这种方式的b $ b实现),你可能需要

才能找到类似的东西

#ifndef __SIZE_T

#define __SIZE_T

typedef unsigned int size_t;

#endif


....意味着在这个特定的实现`size_t''是
一个`unsigned int''。其他实现做出了其他选择。

(预处理器的东西 - 不需要完全符合这里显示的形式

- 确保你的程序只包含一个

`typedef''for`size_t''即使它包含了几个标题

来声明它。)


一般指导:如果你想表达一些东西的大小

或某些东西中的字符数,你应该使用

a`size_t''这样做。有些人还认为数组

指数是一种代理指数。对于一个大小,所以`size_t''应该用于数组索引的
;我认为这个论点很有价值,但我承认我通常会忽略它。


-

Eric Sosman
es*****@acm-dot-org.inva


" Eric Sosman" < ES ***** @ ACM-点org.invalid>在消息中写道

新闻:O _ ******************** @ comcast.com ...
"Eric Sosman" <es*****@acm-dot-org.invalid> wrote in message
news:O_********************@comcast.com...
一般指导:如果你想表达一些东西的大小或某些东西中的字符数,你应该使用
一个`size_t''值来表达。有些人还认为数组
索引是一种代理。对于一个大小,所以`size_t''也应该用于数组索引;我在论证中看到了优点,但承认我通常无视它。
General guidance: If you want to express the size of something
or the number of characters in something, you should probably use
a `size_t'' value to do so. Some people also hold that an array
index is a sort of "proxy" for a size, so `size_t'' should be used
for array indices as well; I see merit in the argument but confess
that I usually disregard it.




我是推荐使用''size_t''的人之一一个数组索引,

,因为它能够代表给定实现上任何可能大小数组的任何可能的索引值




-Mike



I''m one of those who recommend using ''size_t'' for an array index,
because it will be able to represent any possible index value for
any possible size array on a given implementation.

-Mike




Eric Sosman写道:

Eric Sosman wrote:


`size_t ''是一种类型.................


`size_t'' is a type .................



非常感谢size_t的精彩描述。


Candice


Thanks a lot for a wonderful description of size_t.

Candice


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

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