gpt4 book ai didi

c++ - 在哪里可以找到 size_t 的定义?

转载 作者:行者123 更新时间:2023-11-30 16:26:01 24 4
gpt4 key购买 nike

我看到用这种类型定义的变量,但我不知道它来自哪里,也不知道它的目的是什么。为什么不使用 int 或 unsigned int ? (其他“类似”类型呢?Void_t 等)。

最佳答案

来自Wikipedia

The stdlib.h and stddef.h header files define a datatype called size_t1 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.

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

The following types and macros are defined in the standard header stddef.h

<snip>

size_t

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

关于c++ - 在哪里可以找到 size_t 的定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53191941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com