- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
不包含头文件就无法定义native算子的结果不是很麻烦吗?
据此page , size_t
在头文件 cstddef、cstdio、cstring、ctime 和 cstdlib 中定义。因此,如果这些头文件都不包含,那么 size_t
应该是未定义的。但是,以下程序编译时没有任何警告(使用 MSVC 2015RC)。
int main()
{
auto d_Size = sizeof( int );
return 0;
}
似乎 size_t
有点像是原生类型和 typedef 之间的 SCSS 。标准是怎么说的?
最佳答案
5.3.3 Sizeof [expr.sizeof]
1) The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is an unevaluated operand (Clause 5), or a parenthesized type-id. The sizeof operator shall not be applied to an expression that has function or incomplete type, to the parenthesized name of such types, or to a glvalue that designates a bit-field. sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1. The result of sizeof applied to any other fundamental type (3.9.1) is implementation-defined. [ Note: in particular, sizeof(bool), sizeof(char16_t), sizeof(char32_t), and sizeof(wchar_t) are implementation-defined.75 — end note ] [ Note: See 1.7 for the definition of byte and 3.9 for the definition of object representation. — end note ]
6) The result of sizeof and sizeof... is a constant of type std::size_t. [ Note: std::size_t is defined in the standard header
<cstddef>
(18.2). — end note ]
但是,std::size_t
只是一个类型别名。 sizeof
运算符无需“访问”类型别名即可返回其结果; sizeof
的结果是一些基本类型(实现定义),然后别名为 std::size_t
在 <cstddef>
.
另请注意,在 C++ 中 typedef
或 using
不定义新类型(即强类型),而只定义别名(即它们的typeid
相同)。因此,在您的情况下,auto
只是推断 sizeof
返回的基本类型运算符,与类型别名 std::size_t
相同.编译器没问题。
关于c++ - size_t 和 sizeof 不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30206065/
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 个答
我是一名优秀的程序员,十分优秀!