unsigned int类型与为size_t [英] unsigned int vs. size_t

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

问题描述

我注意到,现代的C和C ++ code似乎使用为size_t 而不是 INT / <$的C $ C> unsigned int类型 pretty多少无处不在 - 从C字符串函数的STL参数。我很好奇,这样做的原因和它带来的好处。

I notice that modern C and C++ code seems to use size_t instead of int/unsigned int pretty much everywhere - from parameters for C string functions to the STL. I am curious as to the reason for this and the benefits it brings.

推荐答案

为size_t 类型是无符号整数类型,它的结果 sizeof的运营商(和 offsetof 运营商),因此它是保证足够大,以包含您的系统可以处理的最大对象的大小(例如,8GB的静态数组)。

The size_t type is the unsigned integer type that is the result of the sizeof operator (and the offsetof operator), so it is guaranteed to be big enough to contain the size of the biggest object your system can handle (e.g., a static array of 8Gb).

为size_t 键入可能要比比 unsigned int类型做大,等于或更小,你的编译器可能会使假设它进行优化。

The size_t type may be bigger than, equal to, or smaller than an unsigned int, and your compiler might make assumptions about it for optimization.

您可能会发现更多的C99标准precise信息,部分7.17,其草案可在互联网上的pdf 的格式,或在C11标准,部分7.19,也可作为 /sc22/wg14/www/docs/n1570.pdf\">pdf草案。

You may find more precise information in the C99 standard, section 7.17, a draft of which is available on the Internet in pdf format, or in the C11 standard, section 7.19, also available as a pdf draft.

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

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