- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
size_t
和 std::size_t
在声明的位置、应在何时使用以及任何其他区别特性方面有何区别?
最佳答案
C 的 size_t
和 C++ 的 std::size_t
都是一样的。
在 C 中,它在 <stddef.h>
中定义在 C++ 中,它在 <cstddef>
中定义其内容与 C header 相同(请参阅下面的引用)。其定义为 sizeof 运算符的result 的无符号整数类型。
C 标准在 §17.7/2 中说,
size_t which is the unsigned integer type of the result of the sizeof operator
C++ 标准在 §18.1/3 中说(关于 cstddef
header ),
The contents are the same as the Standard C library header , with the following changes.
是的,两者都是一样的; 唯一的区别是 C++ 定义了 size_t
在 std
命名空间。
还请注意,上面的行也说“有以下更改”,这不是指size_t
.它更确切地说是指 C++ 对语言(C 中不存在)的新添加(大部分),它们也在同一个标题中定义。
维基百科有关于 size_t 的范围和存储大小的非常好的信息:
Range and storage size of size_t
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.
According to the 1999 ISO C standard (C99), size_t is an unsigned integer type of at least 16 bits.
其余的可以从 this page 阅读。在维基百科。
关于c++ - size_t 和 std::size_t 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5813700/
error C2664: 'errno_t wcstombs_s(size_t *,char *,size_t,const wchar_t *,size_t)' : cannot convert pa
size_t有什么区别和 std::size_t在声明它们的位置,何时应该使用它们以及任何其他差异化功能方面? 最佳答案 C的size_t和 C++ 的 std::size_t都是一样的。 在 C 中
刚读完: Does "std::size_t" make sense in C++? 我意识到使用 ::size_t不符合标准(虽然我的编译器支持)当你#include .我想遵守标准,但我不想在前
有什么理由不假设 SIZE_T 是 Microsoft 的 Visual C/C++ 编译器上 size_t 的类型定义? Windows intsafe.h 函数确实包括从一个函数到另一个函数的安全
size_t 和 std::size_t 在声明的位置、应在何时使用以及任何其他区别特性方面有何区别? 最佳答案 C 的 size_t和 C++ 的 st
在某些 Windows API 调用中,我得到:cannot convert argument 6 from 'size_t *' to 'SIZE_T *' . This answer告诉我SIZE
将迭代器条件右操作数从 size_t 转换为 int 更好,还是迭代可能超过 int 的最大值?答案实现具体吗? int a; for (size_t i = 0; i (i)) (有关 numeri
我尝试了三个连续的行(每个单独一个),但是没有一个起作用。 为什么?? int main() { size_t j{8}; char arr[static_cast(j)]={'t'}
我的 C++ 知识一塌糊涂。我有 Apple 提供的代码,他们像往常一样提供了不完整的解决方案。 在此代码中,他们提供了两个空的方法 header : - (NSString *)encodeBase
这是证据: inline constexpr std::size_t prev(std::size_t i) { --i; return i; } int main() { s
我对 size_t 的某些行为感到困惑我注意到: size_t zero = 0x1 << 32; size_t big = 0x1 << 31; size_t not_as_big = 0x1 <<
size_t 在哪里什么时候我什么都没有? 总是假设 size_t 是否合理? == std::size_t ? 什么时候应该使用 size_type在 std容器(string::size_type
我在为 32 位编译时遇到此错误。相同的文件在 64 位 Windows 上编译没有错误 1>c:\project\test.cpp(1317) : error C2664: 'StringCbCop
我希望只有一个模板函数。所以我想到了…… template > || std::is_same_v > > > std::ostream& op
我正在使用 Visual Studio 2017 社区版。它允许我在没有适当包含的情况下同时使用 size_t 和 std::size_t。它似乎适用于大多数 std 库。我认为这是因为图书馆本身的一
我可能要疯了,但我认为我从未在 C++ 中看到过这种情况(尽管我的引用代码是在 C 中)。为什么这里代码的返回值上有一个static,有什么影响?我认为我从未见过类范围之外的静态函数(但显然 C 没有
它没有在 std::string 中明确列出 constructor doc ,(编辑: 这里的人说我应该引用实际的 cppreference 而不是 cplusplus.com)但显然它有效。这意味
将 -1 分配给 size_t 类型的变量 t 并检查它与 -1 和 4294967295(FFFFFFFF,2 对-1 的补充;我的系统是64 位;值可能因系统而异),那么在这两种情况下,它都返回
我正在实现循环数组数据结构,其代码如下所示: struct CircularArrayException : public std::exception { std::string msg;
这个问题在这里已经有了答案: how to pass 2 dimensional array if both dimensions are unknown at compile time (5 个答
我是一名优秀的程序员,十分优秀!