简体   繁体   English

何时/何地/为什么size_t不是单位?

[英]When/where/why is a size_t not a uint?

I've been getting a lot of criticism for using uint instead of size_t , but every time I check the toolchain I am working with turns out size_t is defined as a uint . 使用uint而不是size_t引起了很多批评,但是每次我检查使用的工具链时,结果size_t被定义为uint

Are there any compiler implementations where size_t is actually not a uint ? 是否有任何编译器实现,其中size_t实际上不是uint What are the grounds for that criticism? 这种批评的依据是什么?

size_t is the "size matching the largest possible address range you can use in the machine" (or some words to roughly that effect). size_t是“与您可以在机器中使用的最大可能地址范围相匹配的大小”(或大致代表这种效果的一些单词)。

In particular, size_t will be 64 bits on a 64-bit machine, and 32 bits on a 32-bit system. 特别是,在64位计算机上, size_t将为64位,在32位系统上, size_t将为32位。

I'm assuming uint is short of unsigned int , which is pretty much universally 32 bits (these days, some older systems would be using 16-bit integers). 我假设uint缺少unsigned int ,后者通常是32位(如今,某些较早的系统将使用16位整数)。 So on a 64-bit system, an unsigned int will be 32 bits still, although memory allocations, strings, etc can be larger than 32 bits in size - which would cause problems if you are trying to use uint for the size. 因此,在64位系统上,尽管内存分配,字符串等的大小可能大于32位,但unsigned int仍为32位-如果尝试使用uint作为大小,这会引起问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在 Mac OS X 上使用 size_t 时 uint32_t 和 uint64_t 之间存在歧义? - Why is there ambiguity between uint32_t and uint64_t when using size_t on Mac OS X? size_t定义在哪里? - Where is size_t Defined? 如何测试 size_t -1 是否未定义,其中 size_t 为 0? - How to test if size_t -1 is not undefined, where size_t is 0? 为什么size_t未签名? - Why is size_t unsigned? `std::is_same_v<size_t, uint64_t> 当两种类型都是 8 字节长时,` 评估为 `false`</size_t,> - `std::is_same_v<size_t, uint64_t>` evaluates to `false` when both types are 8 bytes long 为什么 int -> size_t 是缩小转换? - Why is int -> size_t a narrowing conversion? 何时使用 std::size_t? - When to use std::size_t? Flatbuffers 如何在一条消息中发送 uint16_t 标头、size_t 正文大小和 uint8_t 缓冲区 - Flatbuffers how to send in one message uint16_t header, size_t body size and uint8_t buffer 为什么 std::array size_t 和 std::vector 中的 size_type 通常是 size_t? - Why is size_type in std::array size_t and in std::vector usually size_t? 无法将参数5从&#39;SIZE_T *&#39;转换为&#39;size_t *&#39;-为什么? - cannot convert parameter 5 from 'SIZE_T *' to 'size_t *' — why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM