什么是为size_t之间的差异,用C ++诠释? [英] What's the difference between size_t and int in C++?

查看:114
本文介绍了什么是为size_t之间的差异,用C ++诠释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多个C ++的例子我看到一个用size_t类型,我会用一个简单的整型。有什么区别,为什么为size_t应该会更好?

In several C++ examples I see a use of the type size_t where I would have used a simple int. What's the difference, and why size_t should be better?

推荐答案

维基百科的友好:

该文件stdlib.h和STDDEF.H头文件定义了一个名为数据类型的为size_t 这是用来重新present对象的大小。称取大小库函数期望他们size_t类型,而sizeof操作符的计算结果为为size_t。

The stdlib.h and stddef.h header files define a datatype called size_t which is used to represent the size of an object. Library functions that take sizes expect them to be of type size_t, and the sizeof operator evaluates to size_t.

为size_t的实际类型是与平台相关的;一个常见的​​错误是假设为size_t是一样的无符号整数,这可能会导致程序错误,特别是64位架构变得更为prevalent。

The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to programming errors, particularly as 64-bit architectures become more prevalent.

此外,检查为什么为size_t事项

这篇关于什么是为size_t之间的差异,用C ++诠释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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