size_t和std :: size_t之间的区别 [英] Difference between size_t and std::size_t

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

问题描述

size_t std :: size_t 之间的区别在于它们的声明位置应该使用和任何其他区别特征?

What are the differences between size_t and std::size_t in terms of where they are declared, when they should be used and any other differentiating features?

推荐答案

C的 size_t C ++的 std :: size_t 都是相同的。

C's size_t and C++'s std::size_t are both same.

在C中,它在< stddef.h> 中定义,在C ++中定义在< cstddef> ,其内容与C头相同(请参阅下面的引文)。 sizeof 运算符的结果中定义无符号整数类型

In C, it's defined in <stddef.h> and in C++, its defined in <cstddef> whose contents are the same as C header (see the quotation below). Its defined as unsigned integer type of the result of the sizeof operator.

C标准在§17.7/ 2中规定

C Standard says in §17.7/2,



size_t which is the unsigned integer type of the result of the sizeof operator


size_t是无符号整数类型 sizeof 运算符的结果

And C++ Standard says (about cstddef header) in §18.1/3,

> cstddef header)在§18.1/ 3中,

The contents are the same as the Standard C library header , with the following changes.


内容与标准C库标题

唯一的区别是C ++在 std 命名空间中定义 size_t b
$ b

请注意,上面的行还说有以下变化,它不是指 size_t 。它指的是C ++在语言(不存在于C中)中添加的新增内容(大多数),这些内容也在同一个头文件中定义。

Please also notice that the above line also says "with the following changes" which isn't referring to size_t. Its rather referring to the new additions (mostly) made by C++ into the language (not present in C) which are also defined in the same header.

维基百科有关于size_t的范围和存储大小的非常好的信息:

Wikipedia has very good info about range and storage size of size_t:


范围和存储大小size_t

size_t的实际类型是
平台相关 常见错误
是假设size_t与
unsigned int相同,这可能导致
编程错误,[3] [4]移动
从32到64位架构,对于
示例。

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,[3][4] when moving from 32 to 64-bit architecture, for example.

根据1999 ISO C
标准(C99),size_t是unsigned
至少16位的整数类型。

According to the 1999 ISO C standard (C99), size_t is an unsigned integer type of at least 16 bits.

其余的可以从此网页在维基百科。

And the rest you can read from this page at wikipedia.

这篇关于size_t和std :: size_t之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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