[英]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.