我看到用这种类型定义的变量,但我不知道它来自哪里,也不知道它的目的是什么.为什么不使用 int 或 unsigned int?(其他类似"类型呢?Void_t 等).
I see variables defined with this type but I don't know where it comes from, nor what is its purpose. Why not use int or unsigned int? (What about other "similar" types? Void_t, etc).
来自 维基百科
stdlib.h 和 stddef.h 头文件定义了一个名为 size_t1 用于表示对象的大小.接受大小的库函数期望它们是 size_t 类型,并且 sizeof 运算符的计算结果为 size_t.
The
stdlib.handstddef.hheader files define a datatype calledsize_t1 which is used to represent the size of an object. Library functions that take sizes expect them to be of typesize_t, and the sizeof operator evaluates tosize_t.
size_t 的实际类型是平台相关的;一个常见的错误是假设 size_t 与 unsigned int 相同,这会导致编程错误,2 特别是随着 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,2 particularly as 64-bit architectures become more prevalent.
来自 C99 7.17.1/2
以下类型和宏定义在标准头文件stddef.h
The following types and macros are defined in the standard header
stddef.h
size_t
这是sizeof运算符结果的无符号整数类型
which is the unsigned integer type of the result of the sizeof operator
这篇关于我在哪里可以找到 size_t 的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
为什么两个函数的地址相同?Why do two functions have the same address?(为什么两个函数的地址相同?)
为什么 std::function 的初始化程序必须是可复制构Why the initializer of std::function has to be CopyConstructible?(为什么 std::function 的初始化程序必须是可复制构造的?)
混合模板与多态性mixing templates with polymorphism(混合模板与多态性)
我什么时候应该使用关键字“typename"?使用模When should I use the keyword quot;typenamequot; when using templates(我什么时候应该使用关键字“typename?使用模板时)
依赖名称解析命名空间 std/标准库Dependent name resolution amp; namespace std / Standard Library(依赖名称解析命名空间 std/标准库)
gcc 可以编译可变参数模板,而 clang 不能gcc can compile a variadic template while clang cannot(gcc 可以编译可变参数模板,而 clang 不能)